forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

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

getBankQuestions.ts29 lines, 1.1 KiBHistoryRawDownload
1import { client } from "../client";
2import { appendPageParams, normalizePage, type Page, type PageParams } from "../client";
3import type { BankQuestion, BankVisibility } from "../client";
4
5/**
6 * `owner` takes a user id or the literal "me". `visibility` only narrows what the
7 * caller may already see — "private" is effectively their own drafts.
8 */
9export type BankQuestionFilters = PageParams & {
10 subject?: string;
11 owner?: string;
12 q?: string;
13 visibility?: BankVisibility;
14};
15
16export async function getBankQuestions(
17 params?: BankQuestionFilters,
18 signal?: AbortSignal,
19): Promise<Page<BankQuestion>> {
20 const query = new URLSearchParams();
21 if (params?.subject) query.set("subject", params.subject);
22 if (params?.owner) query.set("owner", params.owner);
23 if (params?.q) query.set("q", params.q);
24 if (params?.visibility) query.set("visibility", params.visibility);
25 appendPageParams(query, params);
26 const value = query.toString();
27 const data = await client<unknown>(`/bank-questions${value ? `?${value}` : ""}`, { signal });
28 return normalizePage<BankQuestion>(data);
29}