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