export type GetApiCoursesEnrollmentsArgs = {crn?: string | undefined, classid: string}; export type GetApiCoursesEnrollmentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Lookup enrollments for a class * * GET /courses/enrollments */ export const getApiCoursesEnrollments = async (args: GetApiCoursesEnrollmentsArgs, options?: GetApiCoursesEnrollmentsOptions) => { const {baseUrl = "https://www.rcac.purdue.edu/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.crn != null) query.append("crn", String(args.crn)) if (args.classid != null) query.append("classid", String(args.classid)) const url = `${baseUrl.replace(/\/+$/, '')}/courses/enrollments${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };