hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { client } from "../client"; |
| 2 | import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; |
| 3 | import type { Role, User } from "../client"; |
| 4 | |
| 5 | export type UserListParams = PageParams & { |
| 6 | /** Keep only these roles; comma-joined on the wire, omitted when empty. */ |
| 7 | roles?: Role[]; |
| 8 | }; |
| 9 | |
| 10 | export async function getUsers(params?: UserListParams, signal?: AbortSignal): Promise<Page<User>> { |
| 11 | const query = new URLSearchParams(); |
| 12 | appendPageParams(query, params); |
| 13 | // `!= null`/blank guards are load-bearing: the API 400s on a |
| 14 | // present-but-empty value (`?roles=`), so an empty list drops the key. |
| 15 | const roles = (params?.roles ?? []).map((role) => role.trim()).filter((role) => role !== ""); |
| 16 | if (roles.length) query.set("roles", roles.join(",")); |
| 17 | const suffix = query.size ? `?${query}` : ""; |
| 18 | const data = await client<unknown>(`/users${suffix}`, { signal }); |
| 19 | return normalizePage<User>(data); |
| 20 | } |