refactor: modularize road management modules

This commit is contained in:
2026-06-17 13:31:25 +05:30
parent 9bb740e446
commit 182d4ac293
41 changed files with 2386 additions and 1894 deletions

View File

@@ -1,11 +1,10 @@
import axiosClient from '../axios/axios';
import { API_ROUTES } from '@/constants/apiRoutes';
import type { Role, RoleListParams, RoleListResponse, RoleRequest } from '@/types';
const ROLES_ENDPOINT = 'api/roles';
export const roleService = {
getRoles: async (params?: RoleListParams): Promise<RoleListResponse> => {
const response = await axiosClient.get<RoleListResponse>(ROLES_ENDPOINT, {
const response = await axiosClient.get<RoleListResponse>(API_ROUTES.ROLES.BASE, {
params: {
skip: params?.skip ?? 0,
limit: params?.limit ?? 10,
@@ -22,19 +21,19 @@ export const roleService = {
},
getRoleById: async (id: number): Promise<Role> => {
const response = await axiosClient.get<Role>(`${ROLES_ENDPOINT}/${id}`);
const response = await axiosClient.get<Role>(API_ROUTES.ROLES.DETAIL(id));
return response.data;
},
saveRole: async (payload: RoleRequest): Promise<Role> => {
const response = payload.id
? await axiosClient.put<Role>(ROLES_ENDPOINT, payload)
: await axiosClient.post<Role>(ROLES_ENDPOINT, payload);
? await axiosClient.put<Role>(API_ROUTES.ROLES.BASE, payload)
: await axiosClient.post<Role>(API_ROUTES.ROLES.BASE, payload);
return response.data;
},
updateRoleStatus: async (id: number, isActive: boolean): Promise<Role> => {
const response = await axiosClient.patch<Role>(`${ROLES_ENDPOINT}/${id}/status`, {
const response = await axiosClient.patch<Role>(API_ROUTES.ROLES.STATUS(id), {
is_active: isActive,
});
return response.data;