import {z} from 'zod' export type UpdateWorkTaskDto = {title?: (string | null) | undefined, description?: (string | null) | undefined, patientId?: (string | null) | undefined, assignedToId?: (string | null) | undefined, category?: (string | null) | undefined, priority?: (string | null) | undefined, dueDate?: (string | null) | undefined, callbackType?: (string | null) | undefined, promisedById?: (string | null) | undefined}; export type UpdateApiWorkTasksIdArgs = {id: string, body: UpdateWorkTaskDto}; export type UpdateApiWorkTasksIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const workTaskPatientSummaryDto = z.object({id: z.string().optional(), name: z.string().optional(), species: z.string().nullable().optional(), ownerId: z.string().nullable().optional(), ownerName: z.string().nullable().optional(), ownerPhone: z.string().nullable().optional()}); export const workTaskUserSummaryDto = z.object({id: z.string().optional(), name: z.string().optional(), role: z.string().nullable().optional()}); export const workTaskNoteDto = z.object({id: z.string().optional(), workTaskId: z.string().optional(), authorId: z.string().optional(), authorName: z.string().nullable().optional(), content: z.string().optional(), createdAt: z.string().optional()}); export const workTaskDto = z.object({id: z.string().optional(), title: z.string().optional(), description: z.string().nullable().optional(), patientId: z.string().nullable().optional(), patient: workTaskPatientSummaryDto.nullable().optional(), assignedToId: z.string().nullable().optional(), assignedTo: workTaskUserSummaryDto.nullable().optional(), createdById: z.string().nullable().optional(), createdBy: workTaskUserSummaryDto.nullable().optional(), status: z.string().optional(), category: z.string().optional(), priority: z.string().optional(), dueDate: z.string().nullable().optional(), completedAt: z.string().nullable().optional(), completedById: z.string().nullable().optional(), completedBy: workTaskUserSummaryDto.nullable().optional(), notes: z.array(workTaskNoteDto).optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), callbackType: z.string().nullable().optional(), promisedById: z.string().nullable().optional(), promisedBy: workTaskUserSummaryDto.nullable().optional(), outcome: z.string().nullable().optional(), escalated: z.boolean().optional(), entityType: z.string().nullable().optional(), entityId: z.string().nullable().optional(), emissionSource: z.string().optional(), generatedByRuleId: z.string().nullable().optional(), triggerEventType: z.string().nullable().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 }; /** * Update a work task * * PUT /WorkTasks/{id} */ export const updateApiWorkTasksId = async (args: UpdateApiWorkTasksIdArgs, options?: UpdateApiWorkTasksIdOptions) => { const {baseUrl = "https://api.clinicos.vet/backend/business", 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 ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/WorkTasks/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(workTaskDto, await res.json()) };