refactor: modularize road management modules
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user