43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import axiosClient from '../axios/axios';
|
|
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, {
|
|
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>(`${ROLES_ENDPOINT}/${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);
|
|
return response.data;
|
|
},
|
|
|
|
updateRoleStatus: async (id: number, isActive: boolean): Promise<Role> => {
|
|
const response = await axiosClient.patch<Role>(`${ROLES_ENDPOINT}/${id}/status`, {
|
|
is_active: isActive,
|
|
});
|
|
return response.data;
|
|
},
|
|
};
|