forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

getUsers.ts20 lines, 936 bytesHistoryRawDownload
1import { client } from "../client";
2import { appendPageParams, normalizePage, type Page, type PageParams } from "../client";
3import type { Role, User } from "../client";
4
5export type UserListParams = PageParams & {
6 /** Keep only these roles; comma-joined on the wire, omitted when empty. */
7 roles?: Role[];
8};
9
10export 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}