export type BookExamRequest = {courseShortcode: string, questionId?: number | undefined, questionOption?: number | undefined, requestReason?: string | undefined}; export type CreateApiExamsExamIdBookingArgs = {examId: number, body: BookExamRequest}; export type CreateApiExamsExamIdBookingOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Book exam | Prenota esame * * POST /exams/{examId}/booking */ export const createApiExamsExamIdBooking = async (args: CreateApiExamsExamIdBookingArgs, options?: CreateApiExamsExamIdBookingOptions) => { const {baseUrl = "https://app.didattica.polito.it/api", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/exams/${encodeURIComponent(String(args.examId))}/booking${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };