fix: filter out available bedtypes
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user