import {z} from 'zod' export type TrainingCompanyAssessmentWrite = {id?: string | undefined, created?: string | undefined, modified?: string | undefined, passing_grade?: number | undefined, retake_status?: ('optional' | 'force_retake' | 'force_continue') | undefined, is_active?: boolean | undefined, position?: number | undefined, polymorphic_ctype?: number | undefined, company: string, created_by?: (string | null) | undefined, curriculum: string, assessment: string, lessons_to_skip?: Array | undefined}; export type CreateApiApiAssessmentsCompanyArgs = {body: TrainingCompanyAssessmentWrite}; export type CreateApiApiAssessmentsCompanyOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const trainingCompanyAssessmentWrite = z.object({id: z.string().optional(), created: z.string().optional(), modified: z.string().optional(), passing_grade: z.number().int().gte(-2147483648).lte(2147483647).optional(), retake_status: z.enum(["optional", "force_retake", "force_continue"]).optional(), is_active: z.boolean().optional(), position: z.number().int().gte(-32768).lte(32767).optional(), polymorphic_ctype: z.number().int().optional(), company: z.string(), created_by: z.string().nullable().optional(), curriculum: z.string(), assessment: z.string(), lessons_to_skip: z.array(z.string()).optional()}); 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 }; /** * POST /api/assessments/company */ export const createApiApiAssessmentsCompany = async (args: CreateApiApiAssessmentsCompanyArgs, options?: CreateApiApiAssessmentsCompanyOptions) => { const {baseUrl = "https://app.haekka.com", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/assessments/company${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 validateResponse(trainingCompanyAssessmentWrite, await res.json()) };