import {z} from 'zod' export type UpdateApiApiAbsenceintervalAbsenceIntervalIdCancelArgs = {absenceIntervalId: number}; export type UpdateApiApiAbsenceintervalAbsenceIntervalIdCancelOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const intectAbsenceIntervalStatus = z.object({StaticDataId: z.number().int().optional(), Key: z.string().optional(), Id: z.number().int().optional(), Name: z.string().optional(), Description: z.string().optional(), SortKey: z.string().optional()}); export const intectAbsenceInterval: z.ZodType = z.object({Id: z.number().int().optional(), UserEmploymentId: z.number().int().optional(), SalaryStatementId: z.number().int().nullable().optional(), SalaryTypeId: z.number().int().nullable().optional(), AbsenceTypeIdentifier: z.string().optional(), OriginalStartDate: z.string().optional(), CurrentPayslipStartDate: z.string().nullable().optional(), EndDate: z.string().nullable().optional(), HoursTotal: z.number().nullable().optional(), KarensHours: z.number().nullable().optional(), ExtendsIntervalId: z.number().int().nullable().optional(), DaysTotal: z.number().nullable().optional(), AbsenceIntervalTypeId: z.number().int().optional(), AbsenceIntervalOptionId: z.number().int().nullable().optional(), NoticeDate: z.string().nullable().optional(), LastSalaryDate: z.string().nullable().optional(), IsPaid: z.boolean().nullable().optional(), AbsencePercentage: z.number().nullable().optional(), ExternalId: z.string().optional(), AmeldingReportedDate: z.string().nullable().optional(), AbsenceIntervalStatusId: z.number().int().nullable().optional(), EndDateReportedInAmeldingDate: z.string().nullable().optional(), ForcedAmount: z.number().nullable().optional(), PreviousInterval: z.lazy(() => intectAbsenceInterval.optional()), DaysInCurrentPayslip: z.number().int().optional(), Status: intectAbsenceIntervalStatus.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 }; /** * Rejects the absence interval record. * * PUT /api/absenceinterval/{absenceIntervalId}/cancel * * Also accepts auth: ApiKey */ export const updateApiApiAbsenceintervalAbsenceIntervalIdCancel = async (args: UpdateApiApiAbsenceintervalAbsenceIntervalIdCancelArgs, options?: UpdateApiApiAbsenceintervalAbsenceIntervalIdCancelOptions) => { const {baseUrl = "https://api.intect.app", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/absenceinterval/${encodeURIComponent(String(args.absenceIntervalId))}/cancel${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(intectAbsenceInterval, await res.json()) };