hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBc35a83aBurak Boduroğlu4 months ago440 commits
| 1 | import { client } from "../client"; |
| 2 | import { appendPageParams, normalizePage, type Page, type PageParams } from "../client"; |
| 3 | import type { Course, CourseKind } from "../client"; |
| 4 | |
| 5 | export type CourseListParams = PageParams & { |
| 6 | kind?: CourseKind; |
| 7 | q?: string; |
| 8 | term_id?: string; |
| 9 | }; |
| 10 | |
| 11 | export 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 | |
| 22 | export 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 | } |