import {z} from 'zod' export type EditCity = {name?: string | undefined}; export type EditState = {name?: string | undefined}; export type EditCountry = {iso2?: string | undefined}; export type AddRestaurantCuisine = {id?: number | undefined}; export type AddRestaurantPhoto = {image?: string | undefined}; export type AddImage = {attachment?: string | undefined, image_data?: string | undefined}; export type EditRestaurant = {user_id?: number | undefined, name?: unknown | undefined, phone?: unknown | undefined, mobile?: unknown | undefined, mobile_code?: unknown | undefined, fax?: unknown | undefined, contact_name?: unknown | undefined, contact_phone?: unknown | undefined, website?: unknown | undefined, address1?: unknown | undefined, address?: unknown | undefined, zip_code?: unknown | undefined, city?: EditCity | undefined, state?: EditState | undefined, country?: EditCountry | undefined, latitude?: number | undefined, longitude?: number | undefined, sales_tax?: number | undefined, minimum_order_for_booking?: number | undefined, is_allow_users_to_door_delivery_order?: number | undefined, estimated_time_to_delivery?: number | undefined, delivery_charge?: number | undefined, delivery_miles?: number | undefined, is_active?: number | undefined, cuisine?: Array | undefined, restaurant_photos?: Array | undefined, shop_trading_certificate?: AddImage | undefined}; export type UpdateApiRestaurantsRestaurantIdArgs = {restaurantId: number, body: EditRestaurant}; export type UpdateApiRestaurantsRestaurantIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const restaurant = z.object({id: z.number().int().optional(), created_at: z.string().optional(), updated_at: z.string().optional(), name: z.string().optional(), email: z.string().optional(), phone: z.string().optional(), mobile: z.string().optional(), fax: z.string().optional(), contact_name: z.string().optional(), contact_phone: z.string().optional(), website: z.string().optional(), address1: z.string().optional(), address: z.string().optional(), zip_code: z.string().optional(), latitude: z.number().optional(), longitude: z.number().optional(), sales_tax: z.number().optional(), minimum_order_for_booking: z.number().optional(), is_allow_users_to_door_delivery_order: z.number().int().optional(), estimated_time_to_delivery: z.number().int().optional(), delivery_charge: z.number().optional(), delivery_miles: z.number().int().optional(), slug: z.string().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 restaurant by its id * * PUT /restaurants/{restaurantId} */ export const updateApiRestaurantsRestaurantId = async (args: UpdateApiRestaurantsRestaurantIdArgs, options: UpdateApiRestaurantsRestaurantIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/restaurants/${encodeURIComponent(String(args.restaurantId))}${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(restaurant, await res.json()) };