import {z} from 'zod' export type EmployeeTraining = {id?: string | undefined, year?: number | undefined, start_date?: string | undefined, due_date?: (string | null) | undefined, finish_date?: (string | null) | undefined, active?: boolean | undefined, deactivated_date?: string | undefined, active_lesson?: (string | null) | undefined, lessons?: string | undefined, curriculum_title: string, training_items?: string | undefined}; export type PatchApiApiEmployeesIdTrainingsCurriculumIdCloseArgs = {body: EmployeeTraining}; export type PatchApiApiEmployeesIdTrainingsCurriculumIdCloseOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const employeeTraining = z.object({id: z.string().optional(), year: z.number().int().gte(0).lte(32767).optional(), start_date: z.string().optional(), due_date: z.string().nullable().optional(), finish_date: z.string().nullable().optional(), active: z.boolean().optional(), deactivated_date: z.string().optional(), active_lesson: z.string().nullable().optional(), lessons: z.string().optional(), curriculum_title: z.string().min(1), training_items: 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 }; /** * PATCH /api/employees/{id}/trainings/{curriculum_id}/close */ export const patchApiApiEmployeesIdTrainingsCurriculumIdClose = async (args: PatchApiApiEmployeesIdTrainingsCurriculumIdCloseArgs, options?: PatchApiApiEmployeesIdTrainingsCurriculumIdCloseOptions) => { 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/employees/${encodeURIComponent(String(args.id))}/trainings/${encodeURIComponent(String(args.curriculum_id))}/close${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(employeeTraining, await res.json()) };