forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

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

getHomework.ts31 lines, 1.4 KiBHistoryRawDownload
1import { client } from "../client";
2import { appendPageParams, normalizePage, type Page, type PageParams } from "../client";
3import type { Homework } from "../client";
4
5/**
6 * `GET /homework` filters. All optional and AND-ed; a well-formed
7 * `class_course` uuid that names no row answers an empty page. The due bounds
8 * are unix ms and half-open on `due_at`.
9 */
10export type HomeworkListParams = PageParams & {
11 /** Keeps rows not yet due: `due_at >= v`. */
12 due_after?: number;
13 /** Keeps rows already due: `due_at < v`. */
14 due_before?: number;
15 /** Only homework filed against this instance (şube × ders). */
16 class_course?: string;
17};
18
19export async function getHomework(params?: HomeworkListParams, signal?: AbortSignal): Promise<Page<Homework>> {
20 const query = new URLSearchParams();
21 appendPageParams(query, params);
22 // `!= null` is load-bearing: the API 400s on a present-but-empty value, so an
23 // unset param must drop the key, never emit `key=`.
24 if (params?.due_after != null) query.set("due_after", String(params.due_after));
25 if (params?.due_before != null) query.set("due_before", String(params.due_before));
26 const course = params?.class_course?.trim();
27 if (course) query.set("class_course", course);
28 const suffix = query.size ? `?${query}` : "";
29 const data = await client<unknown>(`/homework${suffix}`, { signal });
30 return normalizePage<Homework>(data);
31}