53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import axiosClient from '../axios/axios';
|
|
import { API_ROUTES } from '@/constants/apiRoutes';
|
|
import type {
|
|
Role,
|
|
RoleListParams,
|
|
RoleListResponse,
|
|
RoleRequest,
|
|
} from '@/types';
|
|
|
|
export const roleService = {
|
|
getRoles: async (params?: RoleListParams): Promise<RoleListResponse> => {
|
|
const response = await axiosClient.get<RoleListResponse>(
|
|
API_ROUTES.ROLES.BASE,
|
|
{
|
|
params: {
|
|
skip: params?.skip ?? 0,
|
|
limit: params?.limit ?? 10,
|
|
search_term: params?.search_term,
|
|
name: params?.name,
|
|
display_name: params?.display_name,
|
|
description: params?.description,
|
|
effective_status: params?.effective_status,
|
|
sort_by: params?.sort_by,
|
|
sort_order: params?.sort_order,
|
|
},
|
|
},
|
|
);
|
|
return response.data;
|
|
},
|
|
|
|
getRoleById: async (id: number): Promise<Role> => {
|
|
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>(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>(
|
|
API_ROUTES.ROLES.STATUS(id),
|
|
{
|
|
is_active: isActive,
|
|
},
|
|
);
|
|
return response.data;
|
|
},
|
|
};
|