rbacRoleService.ts
1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { createApiClient } from "../lib/apiClient";
import type { RoleDto } from "../types/role";
const api = createApiClient({
getToken: () => {
try {
return localStorage.getItem("access_token") ?? localStorage.getItem("token") ?? null;
} catch {
return null;
}
},
});
const PATH = "/rbac-role";
export type RbacRoleUpsertInput = {
roleName: string;
roleCode: string;
remark?: string | null;
dataScope?: number | null;
state: boolean;
orderNum?: number | null;
};
export async function createRbacRole(input: RbacRoleUpsertInput): Promise<RoleDto> {
return api.requestJson<RoleDto>({
path: PATH,
method: "POST",
body: input,
});
}
export async function updateRbacRole(id: string, input: RbacRoleUpsertInput): Promise<RoleDto> {
return api.requestJson<RoleDto>({
path: `${PATH}/${encodeURIComponent(id)}`,
method: "PUT",
body: input,
});
}
/**
* Swagger(常见约定):DELETE /api/app/rbac-role,Body 为 ID 数组
*/
export async function deleteRbacRoles(ids: string[]): Promise<void> {
if (!ids.length) return;
await api.requestJson<unknown>({
path: PATH,
method: "DELETE",
body: ids,
});
}
export async function deleteRbacRole(id: string): Promise<void> {
await deleteRbacRoles([id]);
}