hezarfen_frontend
Clone
https://git.tahinli.com/archive/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 { 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 | */ |
| 9 | export type BankQuestionFilters = PageParams & { |
| 10 | subject?: string; |
| 11 | owner?: string; |
| 12 | q?: string; |
| 13 | visibility?: BankVisibility; |
| 14 | }; |
| 15 | |
| 16 | export 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 | } |