import {z} from 'zod' export type PatchApiOrdersOrderIdTasksTaskIdArgs = {orderId: number, taskId: number, body: {title?: string | undefined, description?: string | undefined, taskStatusId?: number | undefined, priority?: ('low' | 'medium' | 'high') | undefined, dueDate?: (string | null) | undefined, assignedTo?: (number | null) | undefined, removeMediaIds?: string | undefined, files?: Array | undefined}}; export type PatchApiOrdersOrderIdTasksTaskIdOptions = {baseUrl?: string | undefined, accessToken?: string | undefined, fetch?: typeof fetch | undefined}; export const taskStatusInfoDto = z.object({id: z.number(), status: z.string(), backgroundColor: z.string().optional(), textColor: z.string().optional(), borderColor: z.string().optional()}); export const userSummaryDto = z.object({id: z.number(), firstName: z.string(), lastName: z.string(), email: z.string()}); export const taskMediaDto = z.object({id: z.number(), filename: z.string(), url: z.string(), contentType: z.string().optional(), size: z.number().optional(), createdAt: z.string()}); export const taskResponseDto = z.object({id: z.number(), orderId: z.number(), title: z.string(), description: z.string().optional(), status: taskStatusInfoDto, priority: z.string(), dueDate: z.string().optional(), isOverdue: z.boolean(), completedAt: z.string().optional(), assignedToUser: userSummaryDto.nullable().optional(), createdByUser: userSummaryDto, media: z.array(taskMediaDto), createdAt: z.string(), updatedAt: z.string()}); 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 task — optional new files (append), removeMediaIds, max 10 total media * * PATCH /orders/{orderId}/tasks/{taskId} */ export const patchApiOrdersOrderIdTasksTaskId = async (args: PatchApiOrdersOrderIdTasksTaskIdArgs, options?: PatchApiOrdersOrderIdTasksTaskIdOptions) => { const {baseUrl = "https://api.findmydocument.net", fetch: fetchFn = fetch, accessToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (accessToken !== undefined) headers.set('authorization', `Bearer ${accessToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/orders/${encodeURIComponent(String(args.orderId))}/tasks/${encodeURIComponent(String(args.taskId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(taskResponseDto, await res.json()) };