forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

getCourses.ts24 lines, 999 bytesHistoryRawDownload
1import { client } from "../client";
2import { appendPageParams, normalizePage, type Page, type PageParams } from "../client";
3import type { Course } from "../client";
4
5/**
6 * `GET /courses` and `GET /courses/me` take `limit`/`offset` and nothing else —
7 * the backend has no kind/term/search filter, and serde drops unknown query
8 * keys silently, so any extra param would look applied while doing nothing.
9 * Narrow the list in the caller instead (see `courses-page.tsx`).
10 */
11export type CourseListParams = PageParams;
12
13export function courseListQuery(params?: CourseListParams): string {
14 if (!params) return "";
15 const query = new URLSearchParams();
16 appendPageParams(query, params);
17 const value = query.toString();
18 return value ? `?${value}` : "";
19}
20
21export async function getCourses(params?: CourseListParams, signal?: AbortSignal): Promise<Page<Course>> {
22 const data = await client<unknown>(`/courses${courseListQuery(params)}`, { signal });
23 return normalizePage<Course>(data);
24}