fix(SW-614): move filtering logic to routes
This commit is contained in:
@@ -22,7 +22,12 @@ import type { LangParams, PageArgs } from "@/types/params"
|
||||
export function preload() {
|
||||
void getProfileSafely()
|
||||
void getCreditCardsSafely()
|
||||
void getRoomAvailability("811", 1, "2024-11-01", "2024-11-02")
|
||||
void getRoomAvailability({
|
||||
hotelId: "811",
|
||||
adults: 1,
|
||||
roomStayStartDate: "2024-11-01",
|
||||
roomStayEndDate: "2024-11-02",
|
||||
})
|
||||
}
|
||||
|
||||
function isValidStep(step: string): step is StepEnum {
|
||||
@@ -45,12 +50,12 @@ export default async function StepPage({
|
||||
const savedCreditCards = await getCreditCardsSafely()
|
||||
const breakfastPackages = await getBreakfastPackages(searchParams.hotel)
|
||||
|
||||
const roomAvailability = await getRoomAvailability(
|
||||
searchParams.hotel,
|
||||
Number(searchParams.adults),
|
||||
searchParams.checkIn,
|
||||
searchParams.checkOut
|
||||
)
|
||||
const roomAvailability = await getRoomAvailability({
|
||||
hotelId: searchParams.hotel,
|
||||
adults: Number(searchParams.adults),
|
||||
roomStayStartDate: searchParams.checkIn,
|
||||
roomStayEndDate: searchParams.checkOut,
|
||||
})
|
||||
|
||||
if (!isValidStep(params.step) || !hotel || !roomAvailability) {
|
||||
return notFound()
|
||||
@@ -103,10 +108,8 @@ export default async function StepPage({
|
||||
<Payment
|
||||
hotelId={searchParams.hotel}
|
||||
otherPaymentOptions={
|
||||
mustBeGuaranteed
|
||||
? []
|
||||
: hotel.data.attributes.merchantInformationData
|
||||
.alternatePaymentOptions
|
||||
hotel.data.attributes.merchantInformationData
|
||||
.alternatePaymentOptions
|
||||
}
|
||||
savedCreditCards={savedCreditCards}
|
||||
mustBeGuaranteed={mustBeGuaranteed}
|
||||
|
||||
@@ -52,23 +52,34 @@ export const getUserTracking = cache(async function getMemoizedUserTracking() {
|
||||
|
||||
export const getHotelData = cache(async function getMemoizedHotelData(
|
||||
hotelId: string,
|
||||
language: string
|
||||
language: string,
|
||||
isCardOnlyPayment?: boolean
|
||||
) {
|
||||
return serverClient().hotel.hotelData.get({
|
||||
hotelId,
|
||||
language,
|
||||
isCardOnlyPayment,
|
||||
})
|
||||
})
|
||||
|
||||
export const getRoomAvailability = cache(
|
||||
async function getMemoizedRoomAvailability(
|
||||
hotelId: string,
|
||||
adults: number,
|
||||
roomStayStartDate: string,
|
||||
roomStayEndDate: string,
|
||||
children?: number,
|
||||
async function getMemoizedRoomAvailability({
|
||||
hotelId,
|
||||
adults,
|
||||
roomStayStartDate,
|
||||
roomStayEndDate,
|
||||
children,
|
||||
promotionCode,
|
||||
rateCode,
|
||||
}: {
|
||||
hotelId: string
|
||||
adults: number
|
||||
roomStayStartDate: string
|
||||
roomStayEndDate: string
|
||||
children?: number
|
||||
promotionCode?: string
|
||||
) {
|
||||
rateCode?: string
|
||||
}) {
|
||||
return serverClient().hotel.availability.rooms({
|
||||
hotelId: parseInt(hotelId),
|
||||
adults,
|
||||
@@ -76,6 +87,7 @@ export const getRoomAvailability = cache(
|
||||
roomStayEndDate,
|
||||
children,
|
||||
promotionCode,
|
||||
rateCode,
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
@@ -26,6 +26,7 @@ export const getRoomsAvailabilityInputSchema = z.object({
|
||||
promotionCode: z.string().optional(),
|
||||
reservationProfileType: z.string().optional().default(""),
|
||||
attachedProfileId: z.string().optional().default(""),
|
||||
rateCode: z.string().optional(),
|
||||
})
|
||||
|
||||
export const getRatesInputSchema = z.object({
|
||||
@@ -35,6 +36,7 @@ export const getRatesInputSchema = z.object({
|
||||
export const getlHotelDataInputSchema = z.object({
|
||||
hotelId: z.string(),
|
||||
language: z.string(),
|
||||
isCardOnlyPayment: z.boolean().optional(),
|
||||
include: z
|
||||
.array(z.enum(["RoomCategories", "NearbyHotels", "Restaurants", "City"]))
|
||||
.optional(),
|
||||
|
||||
@@ -578,6 +578,7 @@ const roomsAvailabilitySchema = z
|
||||
hotelId: z.number(),
|
||||
roomConfigurations: z.array(roomConfigurationSchema),
|
||||
rateDefinitions: z.array(rateDefinitionSchema),
|
||||
mustBeGuaranteed: z.boolean().optional(),
|
||||
}),
|
||||
relationships: linksSchema.optional(),
|
||||
type: z.string().optional(),
|
||||
|
||||
@@ -430,6 +430,7 @@ export const hotelQueryRouter = router({
|
||||
promotionCode,
|
||||
reservationProfileType,
|
||||
attachedProfileId,
|
||||
rateCode,
|
||||
} = input
|
||||
|
||||
const params: Record<string, string | number | undefined> = {
|
||||
@@ -534,6 +535,14 @@ export const hotelQueryRouter = router({
|
||||
query: { hotelId, params: params },
|
||||
})
|
||||
)
|
||||
|
||||
if (rateCode) {
|
||||
validateAvailabilityData.data.mustBeGuaranteed =
|
||||
validateAvailabilityData.data.rateDefinitions.filter(
|
||||
(rate) => rate.rateCode === rateCode
|
||||
)[0].mustBeGuaranteed
|
||||
}
|
||||
|
||||
return validateAvailabilityData.data
|
||||
}),
|
||||
}),
|
||||
@@ -577,7 +586,7 @@ export const hotelQueryRouter = router({
|
||||
get: serviceProcedure
|
||||
.input(getlHotelDataInputSchema)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const { hotelId, language, include } = input
|
||||
const { hotelId, language, include, isCardOnlyPayment } = input
|
||||
|
||||
const params: Record<string, string> = {
|
||||
hotelId,
|
||||
@@ -669,6 +678,11 @@ export const hotelQueryRouter = router({
|
||||
})
|
||||
)
|
||||
|
||||
if (isCardOnlyPayment) {
|
||||
validateHotelData.data.data.attributes.merchantInformationData.alternatePaymentOptions =
|
||||
[]
|
||||
}
|
||||
|
||||
return validateHotelData.data
|
||||
}),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user