import {z} from 'zod' export type GetApiSystemRegistrationBodyRegistrationBodyIdEntryArgs = {page?: number | undefined, items_per_page?: number | undefined, name?: string | undefined, short_name?: string | undefined, status?: string | undefined, sortBy?: (Array<'name' | '-name' | 'short_name' | '-short_name'>) | undefined}; export type GetApiSystemRegistrationBodyRegistrationBodyIdEntryOptions = {baseUrl?: string | undefined, staffshiftOperation?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const registrationBodyEntryResponseDef = z.object({_id: z.string(), updated_at: z.string(), created_at: z.string(), __v: z.number().int(), name: z.string().min(1), short_name: z.string().min(1), registration_body_id: z.string(), status: z.string().optional()}); export const getApiSystemRegistrationBodyRegistrationBodyIdEntryResponse = z.array(registrationBodyEntryResponseDef); 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 }; /** * Retrieve the list of system registration body entry records * * GET /system/registration-body/{registration_body_id}/entry */ export const getApiSystemRegistrationBodyRegistrationBodyIdEntry = async (args: GetApiSystemRegistrationBodyRegistrationBodyIdEntryArgs, options?: GetApiSystemRegistrationBodyRegistrationBodyIdEntryOptions) => { const {baseUrl = "http://localhost:3010/v1", fetch: fetchFn = fetch, staffshiftOperation} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.items_per_page != null) query.append("items_per_page", String(args.items_per_page)) if (args.name != null) query.append("name", String(args.name)) if (args.short_name != null) query.append("short_name", String(args.short_name)) if (args.status != null) query.append("status", String(args.status)) for (const item of args.sortBy ?? []) query.append("sortBy", String(item)) if (staffshiftOperation !== undefined) headers.set('authorization', `Basic ${btoa(`${staffshiftOperation.username}:${staffshiftOperation.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/system/registration-body/${encodeURIComponent(String(args.registration_body_id))}/entry${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(getApiSystemRegistrationBodyRegistrationBodyIdEntryResponse, await res.json()) };