From 1f516c7c20c4ee5d1e9137e8475ded05acc361bc Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Thu, 2 Jan 2025 10:55:32 +0100 Subject: [PATCH] fix: handle undefined values schemas --- .../SelectRate/RoomSelection/RoomCard/index.tsx | 4 ++-- server/routers/hotels/schemas/restaurants.ts | 16 +++++++++------- server/routers/hotels/schemas/room.ts | 6 +++--- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/components/HotelReservation/SelectRate/RoomSelection/RoomCard/index.tsx b/components/HotelReservation/SelectRate/RoomSelection/RoomCard/index.tsx index ba92ce5e3..ee15f3b5e 100644 --- a/components/HotelReservation/SelectRate/RoomSelection/RoomCard/index.tsx +++ b/components/HotelReservation/SelectRate/RoomSelection/RoomCard/index.tsx @@ -150,13 +150,13 @@ export default function RoomCard({
- {occupancy && ( + {occupancy?.total && ( {intl.formatMessage( { id: "booking.guests", }, - { nrOfGuests: occupancy?.total } + { nrOfGuests: occupancy.total } )} )} diff --git a/server/routers/hotels/schemas/restaurants.ts b/server/routers/hotels/schemas/restaurants.ts index 4fd8e295a..658fb7fc5 100644 --- a/server/routers/hotels/schemas/restaurants.ts +++ b/server/routers/hotels/schemas/restaurants.ts @@ -37,14 +37,16 @@ export const restaurantSchema = z .object({ attributes: z.object({ name: z.string().optional(), - isPublished: z.boolean(), + isPublished: z.boolean().default(false), email: z.string().optional(), phoneNumber: z.string().optional(), - externalBreakfast: z.object({ - isAvailable: z.boolean(), - localPriceForExternalGuests: restaurantPriceSchema.optional(), - requestedPriceForExternalGuests: restaurantPriceSchema.optional(), - }), + externalBreakfast: z + .object({ + isAvailable: z.boolean(), + localPriceForExternalGuests: restaurantPriceSchema.optional(), + requestedPriceForExternalGuests: restaurantPriceSchema.optional(), + }) + .optional(), menus: z .array( z.object({ @@ -53,7 +55,7 @@ export const restaurantSchema = z }) ) .default([]), - openingDetails: z.array(restaurantOpeningDetailSchema), + openingDetails: z.array(restaurantOpeningDetailSchema).default([]), content: z.object({ images: z.array(imageSchema), texts: z.object({ diff --git a/server/routers/hotels/schemas/room.ts b/server/routers/hotels/schemas/room.ts index a9e972d06..1de76227d 100644 --- a/server/routers/hotels/schemas/room.ts +++ b/server/routers/hotels/schemas/room.ts @@ -63,9 +63,9 @@ export const roomSchema = z roomTypes: z.array(roomTypesSchema), roomFacilities: z.array(roomFacilitiesSchema), occupancy: z.object({ - total: z.number(), - adults: z.number(), - children: z.number(), + total: z.number().optional(), + adults: z.number().optional(), + children: z.number().optional(), }), roomSize: z.object({ min: z.number(),