From 9112941026767f7d765f40e36209d79a5577c14d Mon Sep 17 00:00:00 2001 From: Fredrik Thorsson Date: Wed, 28 Aug 2024 13:44:48 +0200 Subject: [PATCH] feat(SW-176): set up route --- .../hotelreservation/select-hotel/page.tsx | 14 +++++++++++++- server/routers/hotels/output.ts | 15 ++++++++------- server/routers/hotels/query.ts | 8 ++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx index dd0528d86..939451a06 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/select-hotel/page.tsx @@ -20,6 +20,7 @@ export default async function SelectHotelPage({ setLang(params.lang) // TODO: Use real endpoint. + const tempSearchTerm = "Stockholm" const hotel = tempHotelData.data.attributes const hotels = [hotel] @@ -27,7 +28,18 @@ export default async function SelectHotelPage({ hotelId: "879", }) - const tempSearchTerm = "Stockholm" + const availability = await serverClient().hotel.availability({ + cityId: "8ec4bba3-1c38-4606-82d1-bbe3f6738e54", + roomStayStartDate: "2024-11-01", + roomStayEndDate: "2024-11-02", + adults: 1, + }) + + const filterAvailability = availability?.availability.data.filter( + (hotels) => hotels.attributes.status === "Available" + ) + + console.log(filterAvailability) return (
diff --git a/server/routers/hotels/output.ts b/server/routers/hotels/output.ts index e0df1167b..a3fee6e4d 100644 --- a/server/routers/hotels/output.ts +++ b/server/routers/hotels/output.ts @@ -510,16 +510,17 @@ const availabilitySchema = z.object({ data: z.array( z.object({ attributes: z.object({ - checkInDate: z.date(), - checkOutDate: z.date(), - occupancy: occupancySchema, + checkInDate: z.string(), + checkOutDate: z.string(), + occupancy: occupancySchema.optional(), status: z.string(), hotelId: z.number(), - ratePlanSet: z.string(), - bestPricePerStay: bestPricePerStaySchema, - bestPricePerNight: bestPricePerNightSchema, + ratePlanSet: z.string().optional(), + bestPricePerStay: bestPricePerStaySchema.optional(), + bestPricePerNight: bestPricePerNightSchema.optional(), }), - relationships: linksSchema, + relationships: linksSchema.optional(), + type: z.string().optional(), }) ), }) diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index 5c0d70054..90ae3d58e 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -41,6 +41,14 @@ const getHotelCounter = meter.createCounter("trpc.hotel.get") const getHotelSuccessCounter = meter.createCounter("trpc.hotel.get-success") const getHotelFailCounter = meter.createCounter("trpc.hotel.get-fail") +const availabilityCounter = meter.createCounter("trpc.hotel.availability") +const availabilitySuccessCounter = meter.createCounter( + "trpc.hotel.availability-success" +) +const availabilityFailCounter = meter.createCounter( + "trpc.hotel.availability-fail" +) + async function getHotelId(locale: string, uid: string | null | undefined) { const rawContentStackData = await request(GetHotelPage, { locale,