From 32d12bae58ddeaa1d38ba14d61ff09f1ff235c33 Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Tue, 12 Nov 2024 08:57:45 +0100 Subject: [PATCH] fix: refacotr away optional pricing --- .../(standard)/[step]/@summary/page.tsx | 8 +++---- .../EnterDetails/Summary/index.tsx | 4 ++-- server/routers/hotels/output.ts | 21 +++++++------------ server/routers/hotels/query.ts | 14 +++++++++---- .../enterDetails/bookingData.ts | 4 ++-- 5 files changed, 25 insertions(+), 26 deletions(-) diff --git a/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx index 7002f07bb..ccda720a2 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx @@ -55,12 +55,12 @@ export default async function SummaryPage({ } : { local: { - price: availability.publicRate?.localPrice.pricePerStay, - currency: availability.publicRate?.localPrice.currency, + price: availability.publicRate.localPrice.pricePerStay, + currency: availability.publicRate.localPrice.currency, }, euro: { - price: availability.publicRate?.requestedPrice.pricePerStay, - currency: availability.publicRate?.requestedPrice.currency, + price: availability.publicRate.requestedPrice.pricePerStay, + currency: availability.publicRate.requestedPrice.currency, }, } diff --git a/components/HotelReservation/EnterDetails/Summary/index.tsx b/components/HotelReservation/EnterDetails/Summary/index.tsx index 738f26fd9..72a4dded8 100644 --- a/components/HotelReservation/EnterDetails/Summary/index.tsx +++ b/components/HotelReservation/EnterDetails/Summary/index.tsx @@ -109,11 +109,11 @@ export default function Summary({ setTotalPrice({ local: { price: parsePrice(room.localPrice.price), - currency: room.localPrice.currency!, + currency: room.localPrice.currency, }, euro: { price: parsePrice(room.euroPrice.price), - currency: room.euroPrice.currency!, + currency: room.euroPrice.currency, }, }) }, [room.localPrice, room.euroPrice, setTotalPrice]) diff --git a/server/routers/hotels/output.ts b/server/routers/hotels/output.ts index 23282b04a..08553d882 100644 --- a/server/routers/hotels/output.ts +++ b/server/routers/hotels/output.ts @@ -554,15 +554,14 @@ export const productTypePriceSchema = z.object({ const productSchema = z.object({ productType: z.object({ - public: productTypePriceSchema.optional(), + public: productTypePriceSchema, member: productTypePriceSchema.optional(), }), }) const roomConfigurationSchema = z.object({ status: z.string(), - // TODO: Remove the optional when the API change has been deployed - roomTypeCode: z.string().optional(), + roomTypeCode: z.string(), roomType: z.string(), roomsLeft: z.number(), features: z.array( @@ -825,17 +824,11 @@ export const apiLocationsSchema = z.object({ ), }) -const breakfastPackagePriceSchema = z - .object({ - currency: z.nativeEnum(CurrencyEnum), - price: z.string(), - totalPrice: z.string(), - }) - .default({ - currency: CurrencyEnum.SEK, - price: "0", - totalPrice: "0", - }) // TODO: Remove optional and default when the API change has been deployed +const breakfastPackagePriceSchema = z.object({ + currency: z.nativeEnum(CurrencyEnum), + price: z.string(), + totalPrice: z.string(), +}) export const breakfastPackageSchema = z.object({ code: z.string(), diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index 882eefb6b..192d88e33 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -733,9 +733,15 @@ export const hotelQueryRouter = router({ const rateTypes = selectedRoom.products.find( (rate) => - rate.productType.public?.rateCode === rateCode || + rate.productType.public.rateCode === rateCode || rate.productType.member?.rateCode === rateCode - )?.productType + ) + + if (!rateTypes) { + console.error("No matching rate found") + return null + } + const rates = rateTypes.productType const mustBeGuaranteed = validateAvailabilityData.data.rateDefinitions.filter( @@ -785,8 +791,8 @@ export const hotelQueryRouter = router({ selectedRoom, mustBeGuaranteed, cancellationText, - memberRate: rateTypes?.member, - publicRate: rateTypes?.public, + memberRate: rates?.member, + publicRate: rates.public, bedTypes, } }), diff --git a/types/components/hotelReservation/enterDetails/bookingData.ts b/types/components/hotelReservation/enterDetails/bookingData.ts index 6aad97085..89ca94efb 100644 --- a/types/components/hotelReservation/enterDetails/bookingData.ts +++ b/types/components/hotelReservation/enterDetails/bookingData.ts @@ -16,8 +16,8 @@ export interface BookingData { } type Price = { - price?: string - currency?: string + price: string + currency: string } export type RoomsData = {