forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

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

getAppointments.ts33 lines, 1.6 KiBHistoryRawDownload
1import { client } from "../client";
2import { appendPageParams, normalizePage, type Page, type PageParams } from "../client";
3import 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 */
10export 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
21export 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}