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 ClassGroup, type Page, type PageParams } from "../client"; |
| 3 | |
| 4 | /** |
| 5 | * `GET /classes` list filters. `grade_level` keeps classes on one rung of the |
| 6 | * grade ladder; an omitted key filters nothing. |
| 7 | */ |
| 8 | export type ClassListParams = PageParams & { |
| 9 | grade_level?: number; |
| 10 | }; |
| 11 | |
| 12 | export async function getClasses(params?: ClassListParams, signal?: AbortSignal): Promise<Page<ClassGroup>> { |
| 13 | const query = new URLSearchParams(); |
| 14 | appendPageParams(query, params); |
| 15 | // `!= null` is load-bearing: the API 400s on a present-but-empty value, so |
| 16 | // an unset grade must drop the key, never emit `grade_level=`. |
| 17 | if (params?.grade_level != null) query.set("grade_level", String(params.grade_level)); |
| 18 | const value = query.toString(); |
| 19 | const data = await client<unknown>(`/classes${value ? `?${value}` : ""}`, { signal }); |
| 20 | return normalizePage<ClassGroup>(data); |
| 21 | } |