refactor: api.ts
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import {
|
||||
apiRequest,
|
||||
apiRequestWithMeta,
|
||||
buildCursorQuery,
|
||||
parseCursorPageMeta,
|
||||
type CursorListParams,
|
||||
type CursorPage,
|
||||
type Employee,
|
||||
} from "./_shared";
|
||||
|
||||
// 系统管理级别接口 - 不区分 workspace
|
||||
export async function listPlatformEmployees(
|
||||
input: CursorListParams = {},
|
||||
): Promise<CursorPage<Employee>> {
|
||||
const query = buildCursorQuery(input);
|
||||
const { data, meta } = await apiRequestWithMeta<Employee[]>(
|
||||
`/api/v1/platform/employees?${query}`,
|
||||
);
|
||||
return { items: data, meta: parseCursorPageMeta(meta) };
|
||||
}
|
||||
|
||||
export async function createPlatformEmployee(
|
||||
input: {
|
||||
username: string;
|
||||
display_name: string;
|
||||
email?: string | undefined;
|
||||
password: string;
|
||||
role_code?: "admin" | "developer";
|
||||
},
|
||||
): Promise<Employee> {
|
||||
return apiRequest<Employee>(
|
||||
"/api/v1/platform/employees",
|
||||
{ method: "POST", body: JSON.stringify({ ...input, role_code: input.role_code ?? "developer" }) },
|
||||
);
|
||||
}
|
||||
|
||||
export async function updatePlatformEmployee(
|
||||
userId: string,
|
||||
input: {
|
||||
display_name?: string;
|
||||
email?: string | null;
|
||||
role_code?: "admin" | "developer";
|
||||
status?: "active" | "disabled" | "locked";
|
||||
},
|
||||
): Promise<Employee> {
|
||||
return apiRequest<Employee>(
|
||||
`/api/v1/platform/employees/${userId}`,
|
||||
{ method: "PATCH", body: JSON.stringify(input) },
|
||||
);
|
||||
}
|
||||
|
||||
export async function deletePlatformEmployee(
|
||||
userId: string,
|
||||
): Promise<{ user_id: string; deleted: boolean }> {
|
||||
return apiRequest(
|
||||
`/api/v1/platform/employees/${userId}`,
|
||||
{ method: "DELETE" },
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user