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