From d8d77479b1960bce6c76a8a21ec1bc7a5066f86c Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Fri, 1 Nov 2024 14:41:56 +0100 Subject: [PATCH] fix: filter out available bedtypes --- .../(standard)/[step]/@summary/page.tsx | 38 +++++++++---------- .../(standard)/[step]/page.tsx | 18 ++------- server/routers/hotels/input.ts | 2 +- server/routers/hotels/query.ts | 38 +++++++++++++++++++ .../hotelReservation/enterDetails/bedType.ts | 2 +- 5 files changed, 63 insertions(+), 35 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 ed36a8476..b28dca1a8 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/@summary/page.tsx @@ -17,7 +17,7 @@ export default async function SummaryPage({ getQueryParamsForEnterDetails(selectRoomParams) const availability = await getSelectedRoomAvailability({ - hotelId: parseInt(hotel), + hotelId: hotel, adults, children, roomStayStartDate: fromDate, @@ -35,25 +35,25 @@ export default async function SummaryPage({ const prices = user ? { - local: { - price: availability.memberRate?.localPrice.pricePerStay, - currency: availability.memberRate?.localPrice.currency, - }, - euro: { - price: availability.memberRate?.requestedPrice?.pricePerStay, - currency: availability.memberRate?.requestedPrice?.currency, - }, - } + local: { + price: availability.memberRate?.localPrice.pricePerStay, + currency: availability.memberRate?.localPrice.currency, + }, + euro: { + price: availability.memberRate?.requestedPrice?.pricePerStay, + currency: availability.memberRate?.requestedPrice?.currency, + }, + } : { - local: { - price: availability.publicRate?.localPrice.pricePerStay, - currency: availability.publicRate?.localPrice.currency, - }, - euro: { - price: availability.publicRate?.requestedPrice?.pricePerStay, - currency: availability.publicRate?.requestedPrice?.currency, - }, - } + local: { + price: availability.publicRate?.localPrice.pricePerStay, + currency: availability.publicRate?.localPrice.currency, + }, + euro: { + price: availability.publicRate?.requestedPrice?.pricePerStay, + currency: availability.publicRate?.requestedPrice?.currency, + }, + } return ( room.name === availableRoom) - ?.roomTypes.map((room) => ({ - description: room.mainBed.description, - size: room.mainBed.widthRange, - value: room.code, - })) - return (
- {/* TODO: How to handle no beds found? */} - {bedTypes ? ( + {roomAvailability.bedTypes ? ( - + ) : null} diff --git a/server/routers/hotels/input.ts b/server/routers/hotels/input.ts index ecf4d5cad..16518bc9f 100644 --- a/server/routers/hotels/input.ts +++ b/server/routers/hotels/input.ts @@ -30,7 +30,7 @@ export const getRoomsAvailabilityInputSchema = z.object({ }) export const getSelectedRoomAvailabilityInputSchema = z.object({ - hotelId: z.number(), + hotelId: z.string(), roomStayStartDate: z.string(), roomStayEndDate: z.string(), adults: z.number(), diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index a9b382bd0..ae27a8498 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -40,6 +40,7 @@ import { getRoomsAvailabilityInputSchema, getSelectedRoomAvailabilityInputSchema, type HotelDataInput, + HotelIncludeEnum, } from "./input" import { breakfastPackagesSchema, @@ -57,6 +58,7 @@ import { } from "./utils" import { FacilityCardTypeEnum } from "@/types/components/hotelPage/facilities" +import type { BedType } from "@/types/components/hotelReservation/enterDetails/bedType" import { AvailabilityEnum } from "@/types/components/hotelReservation/selectHotel/selectHotel" import { BreakfastPackageEnum } from "@/types/enums/breakfast" import type { RequestOptionsWithOutBody } from "@/types/fetch" @@ -686,6 +688,7 @@ export const hotelQueryRouter = router({ promotionCode, reservationProfileType, attachedProfileId, + language: toApiLang(ctx.lang), } selectedRoomAvailabilityCounter.add(1, { @@ -766,10 +769,26 @@ export const hotelQueryRouter = router({ throw badRequestError() } + const hotelData = await getHotelData( + { + hotelId, + language: ctx.lang, + include: [HotelIncludeEnum.RoomCategories], + }, + ctx.serviceToken + ) + const selectedRoom = validateAvailabilityData.data.roomConfigurations .filter((room) => room.status === "Available") .find((room) => room.roomTypeCode === roomTypeCode) + const availableRoomsInCategory = + validateAvailabilityData.data.roomConfigurations.filter( + (room) => + room.status === "Available" && + room.roomType === selectedRoom?.roomType + ) + if (!selectedRoom) { console.error("No matching room found") return null @@ -793,6 +812,24 @@ export const hotelQueryRouter = router({ (rate) => rate.rateCode === rateCode )?.cancellationText ?? "" + const bedTypes = availableRoomsInCategory + .map((availRoom) => { + const matchingRoom = hotelData?.included + ?.find((room) => room.name === availRoom.roomType) + ?.roomTypes.find( + (roomType) => roomType.code === availRoom.roomTypeCode + ) + + if (matchingRoom) { + return { + description: matchingRoom.mainBed.description, + size: matchingRoom.mainBed.widthRange, + value: matchingRoom.code, + } + } + }) + .filter((bed): bed is BedType => Boolean(bed)) + selectedRoomAvailabilitySuccessCounter.add(1, { hotelId, roomStayStartDate, @@ -815,6 +852,7 @@ export const hotelQueryRouter = router({ cancellationText, memberRate, publicRate, + bedTypes, } }), }), diff --git a/types/components/hotelReservation/enterDetails/bedType.ts b/types/components/hotelReservation/enterDetails/bedType.ts index 35f41ee27..3948fcae3 100644 --- a/types/components/hotelReservation/enterDetails/bedType.ts +++ b/types/components/hotelReservation/enterDetails/bedType.ts @@ -2,7 +2,7 @@ import { z } from "zod" import { bedTypeSchema } from "@/components/HotelReservation/EnterDetails/BedType/schema" -type BedType = { +export type BedType = { description: string size: { min: number