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 { AppointmentSlot } from "../client"; |
| 4 | |
| 5 | /** |
| 6 | * `GET /appointments/slots` filters. All optional and AND-ed; the list stays |
| 7 | * `starts_at ASC`. `starts_after` is unix ms and half-open on the slot start |
| 8 | * (`starts_at >= v`). |
| 9 | */ |
| 10 | export type SlotListParams = PageParams & { |
| 11 | /** Only slots of the calling staff member; the value is the literal "me". */ |
| 12 | teacher?: "me"; |
| 13 | /** Keeps slots that have started or start later: `starts_at >= v` (unix ms). */ |
| 14 | starts_after?: number; |
| 15 | }; |
| 16 | |
| 17 | export async function getSlots(params?: SlotListParams, signal?: AbortSignal): Promise<Page<AppointmentSlot>> { |
| 18 | const query = new URLSearchParams(); |
| 19 | appendPageParams(query, params); |
| 20 | // `!= null` is load-bearing: the API 400s on a present-but-empty value, so an |
| 21 | // unset param must drop the key, never emit `key=`. |
| 22 | if (params?.starts_after != null) query.set("starts_after", String(params.starts_after)); |
| 23 | if (params?.teacher) query.set("teacher", params.teacher); |
| 24 | const data = await client<unknown>(`/appointments/slots${query.size ? `?${query}` : ""}`, { signal }); |
| 25 | return normalizePage<AppointmentSlot>(data); |
| 26 | } |