forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBc35a83aBurak Boduroğlu4 months ago440 commits

getCourses.ts25 lines, 913 bytesHistoryRawDownload
1import { client } from "../client";
2import { appendPageParams, normalizePage, type Page, type PageParams } from "../client";
3import type { Course, CourseKind } from "../client";
4
5export type CourseListParams = PageParams & {
6 kind?: CourseKind;
7 q?: string;
8 term_id?: string;
9};
10
11export function courseListQuery(params?: CourseListParams): string {
12 if (!params) return "";
13 const query = new URLSearchParams();
14 appendPageParams(query, params);
15 if (params.kind) query.set("kind", params.kind);
16 if (params.q) query.set("q", params.q);
17 if (params.term_id) query.set("term_id", params.term_id);
18 const value = query.toString();
19 return value ? `?${value}` : "";
20}
21
22export async function getCourses(params?: CourseListParams, signal?: AbortSignal): Promise<Page<Course>> {
23 const data = await client<unknown>(`/courses${courseListQuery(params)}`, { signal });
24 return normalizePage<Course>(data);
25}