import {z} from 'zod' export type GetApiCandidateCandidateIdWorkHistoryPerEmployerArgs = {Authorization: unknown, Context: unknown, Accept: 'application/json', 'X-Accept-Timezone'?: string | undefined, start_date_from?: string | undefined, start_date_to?: string | undefined, end_date_from?: string | undefined, end_date_to?: string | undefined, status?: ('unverified' | 'verified') | undefined}; export type GetApiCandidateCandidateIdWorkHistoryPerEmployerOptions = {baseUrl?: string | undefined, staffshift?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const getApiCandidateCandidateIdWorkHistoryPerEmployerResponse = z.array(z.object({_id: z.string(), updated_at: z.string(), created_at: z.string(), __v: z.number().int(), work_type: z.enum(["agency", "contract", "permanent", "student_placement", "part_time"]), employer_name: z.string().min(1).optional(), employer_contact_number: z.string().optional(), employer_location: z.object({address_line1: z.string().min(1).max(100).optional(), address_line2: z.string().min(1).max(100).optional(), city: z.string().min(1).max(100).optional(), province: z.string().min(2).max(100).optional(), country_code: z.string().min(2).max(2), post_code: z.string().min(1).max(100).optional()}).optional(), position: z.string().optional(), position_type: z.enum(["za_allied_professional", "gbr_care_course", "za_care_giver", "gbr_care_worker", "gbr_catering", "gbr_industrial", "gbr_locum", "za_locum", "gbr_locum_allied", "gbr_nurse", "gbr_teacher", "gbr_teaching_support_staff", "gbr_support_administration", "gbr_caretaking_site_services", "za_nurse", "gbr_social_worker", "za_social_worker", "gbr_social_worker_rsw", "gbr_gp", "gbr_odp", "other"]).optional(), job_family_id: z.string().optional(), job_title_id: z.string().optional(), start_date: z.string(), end_date: z.string().optional(), responsibilities: z.string().optional(), leaving_reason: z.string().optional(), candidate_id: z.string(), current: z.boolean(), status: z.string(), job_family_name: z.string().optional(), job_title_name: z.string().optional(), system_generated: z.boolean()})); 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 }; /** * Special Route to retrieves unique list of work history per employer for a specific candidate * * GET /candidate/{candidate_id}/work-history-per-employer */ export const getApiCandidateCandidateIdWorkHistoryPerEmployer = async (args: GetApiCandidateCandidateIdWorkHistoryPerEmployerArgs, options?: GetApiCandidateCandidateIdWorkHistoryPerEmployerOptions) => { const {baseUrl = "http://localhost:3010/v1", fetch: fetchFn = fetch, staffshift} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.Context != null) headers.set("Context", String(args.Context)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args['X-Accept-Timezone'] != null) headers.set("X-Accept-Timezone", String(args['X-Accept-Timezone'])) if (args.start_date_from != null) query.append("start_date_from", String(args.start_date_from)) if (args.start_date_to != null) query.append("start_date_to", String(args.start_date_to)) if (args.end_date_from != null) query.append("end_date_from", String(args.end_date_from)) if (args.end_date_to != null) query.append("end_date_to", String(args.end_date_to)) if (args.status != null) query.append("status", String(args.status)) if (staffshift !== undefined) headers.set('authorization', `Basic ${btoa(`${staffshift.username}:${staffshift.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/candidate/${encodeURIComponent(String(args.candidate_id))}/work-history-per-employer${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(getApiCandidateCandidateIdWorkHistoryPerEmployerResponse, await res.json()) };