import {z} from 'zod' export type CreateApiV2TimeOffTimeOffIdDeclineArgs = {'x-api-version'?: string | undefined, 'x-company-guid'?: string | undefined, time_off_id: number, body: {status_action_message?: (string | null) | undefined}}; export type CreateApiV2TimeOffTimeOffIdDeclineOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV2TimeOffTimeOffIdDeclineResponse = z.object({id: z.number().int(), user_id: z.number().int(), company_id: z.number().int(), from_date: z.string(), to_date: z.string(), partial: z.boolean(), partial_from: z.string().nullable(), partial_to: z.string().nullable(), comments: z.string(), status: z.number().int(), status_action_user_id: z.number().int().nullable(), status_action_message: z.string(), category: z.string(), created: z.string(), amount_of_hours: z.number(), hours: z.array(z.object({date: z.string(), hours: 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 }; /** * Decline Time Off Request * * POST /v2/time_off/{time_off_id}/decline * * Also accepts auth: cookieAuth */ export const createApiV2TimeOffTimeOffIdDecline = async (args: CreateApiV2TimeOffTimeOffIdDeclineArgs, options?: CreateApiV2TimeOffTimeOffIdDeclineOptions) => { const {baseUrl = "https://api.7shifts.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-api-version'] != null) headers.set("x-api-version", String(args['x-api-version'])) if (args['x-company-guid'] != null) headers.set("x-company-guid", String(args['x-company-guid'])) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/time_off/${encodeURIComponent(String(args.time_off_id))}/decline${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(createApiV2TimeOffTimeOffIdDeclineResponse, await res.json()) };