forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

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

getInstanceSessions.ts30 lines, 1.3 KiBHistoryRawDownload
1import { client } from "../client";
2import { appendPageParams, normalizePage, type Page, type PageParams } from "../client";
3import type { CourseSession } from "../client";
4
5/**
6 * `GET /instances/:id/sessions` filters. Both optional and AND-ed, unix ms,
7 * and half-open `[from, to)` on the session start: `starts_at >= starts_after`
8 * and `starts_at < starts_before`.
9 */
10export type InstanceSessionListParams = PageParams & {
11 /** Keeps sessions starting at or after this instant. */
12 starts_after?: number;
13 /** Keeps sessions starting before this instant. */
14 starts_before?: number;
15};
16
17export async function getInstanceSessions(
18 instanceId: string,
19 params?: InstanceSessionListParams,
20 signal?: AbortSignal,
21): Promise<Page<CourseSession>> {
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 data = await client<unknown>(`/instances/${instanceId}/sessions${query.size ? `?${query}` : ""}`, { signal });
29 return normalizePage<CourseSession>(data);
30}