refactor: modularize road management modules
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import axiosClient from '../axios/axios';
|
||||
import { API_ROUTES } from '@/constants/apiRoutes';
|
||||
import type {
|
||||
Tenant,
|
||||
TenantCreateRequest,
|
||||
@@ -7,8 +8,6 @@ import type {
|
||||
TenantUpdateRequest,
|
||||
} from '@/types';
|
||||
|
||||
const TENANTS_ENDPOINT = 'api/superadmin/tenants';
|
||||
|
||||
function toCreatePayload(payload: TenantCreateRequest) {
|
||||
return {
|
||||
name: payload.name,
|
||||
@@ -39,7 +38,7 @@ function toUpdatePayload(payload: TenantUpdateRequest) {
|
||||
|
||||
export const tenantService = {
|
||||
getTenants: async (params?: TenantListParams): Promise<TenantListResponse> => {
|
||||
const response = await axiosClient.get<TenantListResponse>(TENANTS_ENDPOINT, {
|
||||
const response = await axiosClient.get<TenantListResponse>(API_ROUTES.TENANTS.BASE, {
|
||||
params: {
|
||||
skip: params?.skip ?? 0,
|
||||
limit: params?.limit ?? 10,
|
||||
@@ -53,19 +52,22 @@ export const tenantService = {
|
||||
},
|
||||
|
||||
createTenant: async (payload: TenantCreateRequest): Promise<Tenant> => {
|
||||
const response = await axiosClient.post<Tenant>(TENANTS_ENDPOINT, toCreatePayload(payload));
|
||||
const response = await axiosClient.post<Tenant>(
|
||||
API_ROUTES.TENANTS.BASE,
|
||||
toCreatePayload(payload),
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
updateTenant: async (payload: TenantUpdateRequest): Promise<Tenant> => {
|
||||
const response = await axiosClient.put<Tenant>(
|
||||
`${TENANTS_ENDPOINT}/${payload.id}`,
|
||||
API_ROUTES.TENANTS.DETAIL(payload.id),
|
||||
toUpdatePayload(payload),
|
||||
);
|
||||
return response.data;
|
||||
},
|
||||
|
||||
deleteTenant: async (id: number): Promise<void> => {
|
||||
await axiosClient.delete(`${TENANTS_ENDPOINT}/${id}`);
|
||||
await axiosClient.delete(API_ROUTES.TENANTS.DETAIL(id));
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user