fix: filter out room availability based on packages
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
import { redirect } from "next/navigation"
|
||||||
|
|
||||||
|
import { selectRate } from "@/constants/routes/hotelReservation"
|
||||||
import {
|
import {
|
||||||
getPackages,
|
getPackages,
|
||||||
getProfileSafely,
|
getProfileSafely,
|
||||||
@@ -17,6 +20,7 @@ import { SelectRateSearchParams } from "@/types/components/hotelReservation/sele
|
|||||||
import { LangParams, PageArgs, SearchParams } from "@/types/params"
|
import { LangParams, PageArgs, SearchParams } from "@/types/params"
|
||||||
|
|
||||||
export default async function SummaryPage({
|
export default async function SummaryPage({
|
||||||
|
params,
|
||||||
searchParams,
|
searchParams,
|
||||||
}: PageArgs<LangParams, SearchParams<SelectRateSearchParams>>) {
|
}: PageArgs<LangParams, SearchParams<SelectRateSearchParams>>) {
|
||||||
const selectRoomParams = new URLSearchParams(searchParams)
|
const selectRoomParams = new URLSearchParams(searchParams)
|
||||||
@@ -39,6 +43,7 @@ export default async function SummaryPage({
|
|||||||
roomStayEndDate: toDate,
|
roomStayEndDate: toDate,
|
||||||
rateCode,
|
rateCode,
|
||||||
roomTypeCode,
|
roomTypeCode,
|
||||||
|
packageCodes,
|
||||||
})
|
})
|
||||||
const user = await getProfileSafely()
|
const user = await getProfileSafely()
|
||||||
const packages = await getPackages({
|
const packages = await getPackages({
|
||||||
@@ -50,10 +55,10 @@ export default async function SummaryPage({
|
|||||||
packageCodes,
|
packageCodes,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!availability) {
|
if (!availability || !availability.selectedRoom) {
|
||||||
console.error("No hotel or availability data", availability)
|
console.error("No hotel or availability data", availability)
|
||||||
// TODO: handle this case
|
// TODO: handle this case
|
||||||
return null
|
redirect(selectRate[params.lang])
|
||||||
}
|
}
|
||||||
|
|
||||||
const prices =
|
const prices =
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default async function StepPage({
|
|||||||
toDate,
|
toDate,
|
||||||
} = getQueryParamsForEnterDetails(selectRoomParams)
|
} = getQueryParamsForEnterDetails(selectRoomParams)
|
||||||
|
|
||||||
const { adults, children, roomTypeCode, rateCode } = rooms[0] // TODO: Handle multiple rooms
|
const { adults, children, roomTypeCode, rateCode, packages } = rooms[0] // TODO: Handle multiple rooms
|
||||||
|
|
||||||
const childrenAsString = children && generateChildrenString(children)
|
const childrenAsString = children && generateChildrenString(children)
|
||||||
|
|
||||||
@@ -60,6 +60,7 @@ export default async function StepPage({
|
|||||||
roomStayEndDate: toDate,
|
roomStayEndDate: toDate,
|
||||||
rateCode,
|
rateCode,
|
||||||
roomTypeCode,
|
roomTypeCode,
|
||||||
|
packageCodes: packages,
|
||||||
})
|
})
|
||||||
|
|
||||||
const roomAvailability = await getSelectedRoomAvailability({
|
const roomAvailability = await getSelectedRoomAvailability({
|
||||||
@@ -70,6 +71,7 @@ export default async function StepPage({
|
|||||||
roomStayEndDate: toDate,
|
roomStayEndDate: toDate,
|
||||||
rateCode,
|
rateCode,
|
||||||
roomTypeCode,
|
roomTypeCode,
|
||||||
|
packageCodes: packages,
|
||||||
})
|
})
|
||||||
const hotelData = await getHotelData({
|
const hotelData = await getHotelData({
|
||||||
hotelId,
|
hotelId,
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
|
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
|
||||||
|
|
||||||
export const getHotelsAvailabilityInputSchema = z.object({
|
export const getHotelsAvailabilityInputSchema = z.object({
|
||||||
cityId: z.string(),
|
cityId: z.string(),
|
||||||
roomStayStartDate: z.string(),
|
roomStayStartDate: z.string(),
|
||||||
@@ -34,6 +36,7 @@ export const getSelectedRoomAvailabilityInputSchema = z.object({
|
|||||||
attachedProfileId: z.string().optional().default(""),
|
attachedProfileId: z.string().optional().default(""),
|
||||||
rateCode: z.string(),
|
rateCode: z.string(),
|
||||||
roomTypeCode: z.string(),
|
roomTypeCode: z.string(),
|
||||||
|
packageCodes: z.array(z.nativeEnum(RoomPackageCodeEnum)).optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export type GetSelectedRoomAvailabilityInput = z.input<
|
export type GetSelectedRoomAvailabilityInput = z.input<
|
||||||
|
|||||||
@@ -624,6 +624,7 @@ export const hotelQueryRouter = router({
|
|||||||
attachedProfileId,
|
attachedProfileId,
|
||||||
rateCode,
|
rateCode,
|
||||||
roomTypeCode,
|
roomTypeCode,
|
||||||
|
packageCodes,
|
||||||
} = input
|
} = input
|
||||||
|
|
||||||
const params: Record<string, string | number | undefined> = {
|
const params: Record<string, string | number | undefined> = {
|
||||||
@@ -723,17 +724,35 @@ export const hotelQueryRouter = router({
|
|||||||
ctx.serviceToken
|
ctx.serviceToken
|
||||||
)
|
)
|
||||||
|
|
||||||
const selectedRoom = validateAvailabilityData.data.roomConfigurations
|
console.log({ packageCodes })
|
||||||
.filter((room) => room.status === "Available")
|
|
||||||
.find((room) => room.roomTypeCode === roomTypeCode)
|
|
||||||
|
|
||||||
const availableRoomsInCategory =
|
const availableRooms =
|
||||||
validateAvailabilityData.data.roomConfigurations.filter(
|
validateAvailabilityData.data.roomConfigurations.filter((room) => {
|
||||||
(room) =>
|
if (packageCodes) {
|
||||||
room.status === "Available" &&
|
return (
|
||||||
room.roomType === selectedRoom?.roomType
|
room.status === "Available" &&
|
||||||
)
|
room.features.some(
|
||||||
|
(feature) =>
|
||||||
|
packageCodes.includes(feature.code) && feature.inventory > 0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return room.status === "Available"
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log("hrteij", JSON.stringify(availableRooms, null, 4))
|
||||||
|
const selectedRoom = availableRooms.find(
|
||||||
|
(room) => room.roomTypeCode === roomTypeCode
|
||||||
|
)
|
||||||
|
|
||||||
|
const availableRoomsInCategory = availableRooms.filter(
|
||||||
|
(room) => room.roomType === selectedRoom?.roomType
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"availableRoomsInCategory",
|
||||||
|
JSON.stringify(availableRoomsInCategory, null, 4)
|
||||||
|
)
|
||||||
if (!selectedRoom) {
|
if (!selectedRoom) {
|
||||||
console.error("No matching room found")
|
console.error("No matching room found")
|
||||||
return null
|
return null
|
||||||
|
|||||||
Reference in New Issue
Block a user