import {z} from 'zod' export type GetApiTeacherClassesClassIdStudentsStudentIdDashboardArgs = {class_id: string, student_id: string, period?: (string | null) | undefined}; export type GetApiTeacherClassesClassIdStudentsStudentIdDashboardOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const studentProductionResponse = z.object({activity_id: z.string(), activity_type: z.union([z.enum(["evaluation", "devoir", "cours", "controle"]), z.enum(["self_practice", "homework_helper", "remediation"]), z.literal("copy_resume")]), title: z.string(), occurred_at: z.string(), grade: z.number().nullable().optional(), status: z.enum(["non_rendu", "absent", "termine", "en_cours", "interrompu"]).nullable().optional(), target_id: z.string().nullable().optional()}); export const chapterProfilePointResponse = z.object({chapter: z.string(), student_mastery: z.number().nullable().optional(), class_mastery: z.number().nullable().optional()}); export const studentSheetResponse = z.object({student_id: z.string(), display_name: z.string(), class_name: z.string(), period: z.string(), general: z.number().nullable().optional(), by_type: z.record(z.string(), z.number().nullable()).optional(), class_general: z.number().nullable().optional(), class_by_type: z.record(z.string(), z.number().nullable()).optional(), devoirs_done: z.number().int(), devoirs_assigned: z.number().int(), controles_done: z.number().int(), controles_assigned: z.number().int(), autonomy_exercises: z.number().int(), last_activity: z.string().nullable().optional(), productions: z.array(studentProductionResponse), profile: z.array(chapterProfilePointResponse), has_radar: z.boolean(), evaluated_chapters: z.number().int(), total_chapters: z.number().int(), weights: z.record(z.string(), z.number())}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Student Sheet * * GET /teacher/classes/{class_id}/students/{student_id}/dashboard */ export const getApiTeacherClassesClassIdStudentsStudentIdDashboard = async (args: GetApiTeacherClassesClassIdStudentsStudentIdDashboardArgs, options: GetApiTeacherClassesClassIdStudentsStudentIdDashboardOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.period != null) query.append("period", String(args.period)) if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/teacher/classes/${encodeURIComponent(String(args.class_id))}/students/${encodeURIComponent(String(args.student_id))}/dashboard${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 validateResponse(studentSheetResponse, await res.json()) };