23 lines
1.3 KiB
TypeScript
23 lines
1.3 KiB
TypeScript
import { z } from "zod";
|
|
import type { KyInstance } from "ky";
|
|
import { RoleGroupSchema, RoleMemberSchema, RoleSchema, type Role, type RoleGroup, type RoleMember } from "./types.js";
|
|
|
|
export async function listRoles(client: KyInstance, corpId: string, start = 0, count = 2999): Promise<Role[]> {
|
|
const response = await client.get("api/v1/organization/roles", { searchParams: { start: String(start), count: String(count), corpId } });
|
|
const json = (await response.json()) as { items?: unknown[] };
|
|
return z.array(RoleSchema).parse(json.items ?? []);
|
|
}
|
|
|
|
export async function listRoleGroups(client: KyInstance, corpId: string): Promise<RoleGroup[]> {
|
|
const response = await client.get("api/v1/organization/roleGroups", { searchParams: { corpId } });
|
|
const json = (await response.json()) as { items?: unknown[] };
|
|
return z.array(RoleGroupSchema).parse(json.items ?? []);
|
|
}
|
|
|
|
export async function listRoleMembers(client: KyInstance, corpId: string, roleDefId: string): Promise<RoleMember[]> {
|
|
const response = await client.get("api/v1/organization/staffs/byRole", { searchParams: { roleDefId, corpId } });
|
|
const json = (await response.json()) as { items?: unknown[] };
|
|
const items = (json.items ?? []).map((item: any) => item?.staff ?? item);
|
|
return z.array(RoleMemberSchema).parse(items);
|
|
}
|