refactor: modularize road management modules
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import axiosClient from '../axios/axios';
|
||||
import { API_ROUTES } from '@/constants/apiRoutes';
|
||||
import type { Plan, PlanListParams, PlanListResponse, PlanRequest } from '@/types';
|
||||
|
||||
const PLANS_ENDPOINT = 'api/superadmin/plans';
|
||||
|
||||
function toPlanPayload(payload: PlanRequest) {
|
||||
return {
|
||||
name: payload.name,
|
||||
@@ -23,7 +22,7 @@ function toPlanPayload(payload: PlanRequest) {
|
||||
|
||||
export const planService = {
|
||||
getPlans: async (params?: PlanListParams): Promise<PlanListResponse> => {
|
||||
const response = await axiosClient.get<PlanListResponse>(PLANS_ENDPOINT, {
|
||||
const response = await axiosClient.get<PlanListResponse>(API_ROUTES.PLANS.BASE, {
|
||||
params: {
|
||||
skip: params?.skip ?? 0,
|
||||
limit: params?.limit ?? 10,
|
||||
@@ -42,13 +41,13 @@ export const planService = {
|
||||
savePlan: async (payload: PlanRequest): Promise<Plan> => {
|
||||
const requestPayload = toPlanPayload(payload);
|
||||
const response = payload.id
|
||||
? await axiosClient.put<Plan>(`${PLANS_ENDPOINT}/${payload.id}`, requestPayload)
|
||||
: await axiosClient.post<Plan>(PLANS_ENDPOINT, requestPayload);
|
||||
? await axiosClient.put<Plan>(API_ROUTES.PLANS.DETAIL(payload.id), requestPayload)
|
||||
: await axiosClient.post<Plan>(API_ROUTES.PLANS.BASE, requestPayload);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
updatePlanStatus: async (id: number, isActive: boolean): Promise<Plan> => {
|
||||
const response = await axiosClient.patch<Plan>(`${PLANS_ENDPOINT}/${id}/status`, {
|
||||
const response = await axiosClient.patch<Plan>(API_ROUTES.PLANS.STATUS(id), {
|
||||
is_active: isActive,
|
||||
});
|
||||
return response.data;
|
||||
|
||||
Reference in New Issue
Block a user