56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { apiFetch } from './client';
|
|
import { API_ENDPOINTS } from './config';
|
|
|
|
export interface RoleResponse {
|
|
role_id: string;
|
|
role_name: string;
|
|
role_prefix: string;
|
|
description: string | null;
|
|
is_system: boolean;
|
|
is_active: boolean;
|
|
created_at: string;
|
|
}
|
|
|
|
export interface PermissionResponse {
|
|
permission_id: string;
|
|
permission_code: string;
|
|
module: string;
|
|
resource: string;
|
|
action: string;
|
|
description: string | null;
|
|
is_active: boolean;
|
|
}
|
|
|
|
export const rolePermissionService = {
|
|
async getRoles(): Promise<RoleResponse[]> {
|
|
return apiFetch<RoleResponse[]>(API_ENDPOINTS.ROLE_PERM_ROLES_ALL);
|
|
},
|
|
|
|
async createRole(data: { role_name: string; role_prefix: string; description?: string }): Promise<RoleResponse> {
|
|
return apiFetch<RoleResponse>(API_ENDPOINTS.ROLE_PERM_ROLES_CREATE, {
|
|
method: 'POST',
|
|
body: JSON.stringify(data),
|
|
});
|
|
},
|
|
|
|
async deleteRole(roleId: string): Promise<{ detail: string }> {
|
|
return apiFetch<{ detail: string }>(API_ENDPOINTS.ROLE_PERM_ROLES_DELETE(roleId), {
|
|
method: 'DELETE',
|
|
});
|
|
},
|
|
|
|
async getPermissions(): Promise<PermissionResponse[]> {
|
|
return apiFetch<PermissionResponse[]>(API_ENDPOINTS.ROLE_PERM_PERMISSIONS_ALL);
|
|
},
|
|
|
|
async getRolePermissions(roleId: string): Promise<string[]> {
|
|
return apiFetch<string[]>(API_ENDPOINTS.ROLE_PERM_ROLE_GET_PERMISSIONS(roleId));
|
|
},
|
|
|
|
async updateRolePermissions(roleId: string, permissionIds: string[]): Promise<{ detail: string }> {
|
|
return apiFetch<{ detail: string }>(API_ENDPOINTS.ROLE_PERM_ROLE_SET_PERMISSIONS(roleId), {
|
|
method: 'POST',
|
|
body: JSON.stringify({ permission_ids: permissionIds }),
|
|
});
|
|
},
|
|
};
|