From 60ceeaf9c347080994976910438a0adc7016956b Mon Sep 17 00:00:00 2001 From: Tobias Johansson Date: Mon, 28 Oct 2024 11:06:47 +0100 Subject: [PATCH] fix(SW-614): move filtering logic to routes --- .../(standard)/[step]/page.tsx | 25 +++++++++-------- lib/trpc/memoizedRequests/index.ts | 28 +++++++++++++------ server/routers/hotels/input.ts | 2 ++ server/routers/hotels/output.ts | 1 + server/routers/hotels/query.ts | 16 ++++++++++- 5 files changed, 52 insertions(+), 20 deletions(-) diff --git a/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/page.tsx index 689a4d8de..7532c6673 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/(standard)/[step]/page.tsx @@ -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({ = { @@ -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 = { hotelId, @@ -669,6 +678,11 @@ export const hotelQueryRouter = router({ }) ) + if (isCardOnlyPayment) { + validateHotelData.data.data.attributes.merchantInformationData.alternatePaymentOptions = + [] + } + return validateHotelData.data }), }),