diff --git a/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils.ts b/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils.ts index 8dfc76a1d..11de17bee 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils.ts +++ b/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-hotel/utils.ts @@ -1,3 +1,4 @@ +import { getHotelData } from "@/lib/trpc/memoizedRequests" import { serverClient } from "@/lib/trpc/server" import { getLang } from "@/i18n/serverContext" @@ -15,7 +16,7 @@ export async function fetchAvailableHotels( const language = getLang() const hotels = availableHotels.availability.map(async (hotel) => { - const hotelData = await serverClient().hotel.hotelData.get({ + const hotelData = await getHotelData({ hotelId: hotel.hotelId.toString(), language, }) diff --git a/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-rate/page.tsx b/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-rate/page.tsx index 7655dee10..41f68dadb 100644 --- a/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-rate/page.tsx +++ b/app/[lang]/(live)/(public)/hotelreservation/(standard)/select-rate/page.tsx @@ -1,7 +1,11 @@ import { notFound } from "next/navigation" import { dt } from "@/lib/dt" -import { getLocations, getProfileSafely } from "@/lib/trpc/memoizedRequests" +import { + getHotelData, + getLocations, + getProfileSafely, +} from "@/lib/trpc/memoizedRequests" import { serverClient } from "@/lib/trpc/server" import { HotelIncludeEnum } from "@/server/routers/hotels/input" @@ -58,10 +62,7 @@ export default async function SelectRatePage({ : undefined // TODO: Handle multiple rooms const [hotelData, roomsAvailability, packages, user] = await Promise.all([ - serverClient().hotel.hotelData.get({ - hotelId: searchParams.hotel, - language: params.lang, - }), + getHotelData({ hotelId: searchParams.hotel, language: params.lang }), serverClient().hotel.availability.rooms({ hotelId: parseInt(searchParams.hotel, 10), roomStayStartDate: validFromDate, diff --git a/server/routers/hotels/input.ts b/server/routers/hotels/input.ts index 50ec5af4b..303806bdc 100644 --- a/server/routers/hotels/input.ts +++ b/server/routers/hotels/input.ts @@ -50,9 +50,9 @@ export const getRatesInputSchema = z.object({ export const HotelIncludeEnum = z.enum([ "RoomCategories", - "NearbyHotels", - "Restaurants", - "City", + //"NearbyHotels", + //"Restaurants", + //"City", ]) export const getHotelDataInputSchema = z.object({ diff --git a/server/routers/hotels/query.ts b/server/routers/hotels/query.ts index 87db78640..ed84f3f17 100644 --- a/server/routers/hotels/query.ts +++ b/server/routers/hotels/query.ts @@ -279,77 +279,21 @@ export const hotelQueryRouter = router({ throw notFound(`Hotel not found for uid: ${uid}`) } - const apiLang = toApiLang(lang) - const params: Record = { - hotelId, - language: apiLang, - } - - params.include = HotelIncludeEnum.options.join(",") - - getHotelCounter.add(1, { hotelId, lang }) - console.info( - "api.hotels.hotel start", - JSON.stringify({ - query: { hotelId, params }, - }) - ) - const apiResponse = await api.get( - api.endpoints.v1.Hotel.Hotels.hotel(hotelId), + const hotelData = await getHotelData( { - headers: { - Authorization: `Bearer ${ctx.serviceToken}`, - }, - // needs to clear default option as only - // cache or next.revalidate is permitted - cache: undefined, - next: { - revalidate: 60 * 30, // 30 minutes - }, + hotelId, + language: ctx.lang, }, - params + ctx.serviceToken ) - if (!apiResponse.ok) { - const text = await apiResponse.text() - getHotelFailCounter.add(1, { - hotelId, - lang, - error_type: "http_error", - error: JSON.stringify({ - status: apiResponse.status, - statusText: apiResponse.statusText, - text, - }), - }) - console.error( - "api.hotels.hotel error", - JSON.stringify({ - query: { hotelId, params }, - error: { - status: apiResponse.status, - statusText: apiResponse.statusText, - text, - }, - }) - ) - throw serverErrorByStatus(apiResponse.status, apiResponse) - } - const apiJson = await apiResponse.json() - const validatedHotelData = getHotelDataSchema.safeParse(apiJson) + const validatedHotelData = getHotelDataSchema.safeParse(hotelData) if (!validatedHotelData.success) { - getHotelFailCounter.add(1, { - hotelId, - lang, - error_type: "validation_error", - error: JSON.stringify(validatedHotelData.error), - }) - console.error( "api.hotels.hotel validation error", JSON.stringify({ - query: { hotelId, params }, + query: { hotelId }, error: validatedHotelData.error, }) ) @@ -372,26 +316,28 @@ export const hotelQueryRouter = router({ const facilities: Facility[] = [ { - ...apiJson.data.attributes.restaurantImages, id: FacilityCardTypeEnum.restaurant, + headingText: + hotelData?.data.attributes.restaurantImages?.headingText ?? "", + heroImages: + hotelData?.data.attributes.restaurantImages?.heroImages ?? [], }, { - ...apiJson.data.attributes.conferencesAndMeetings, id: FacilityCardTypeEnum.conference, + headingText: + hotelData?.data.attributes.conferencesAndMeetings?.headingText ?? "", + heroImages: + hotelData?.data.attributes.conferencesAndMeetings?.heroImages ?? [], }, { - ...apiJson.data.attributes.healthAndWellness, id: FacilityCardTypeEnum.wellness, + headingText: + hotelData?.data.attributes.healthAndWellness?.headingText ?? "", + heroImages: + hotelData?.data.attributes.healthAndWellness?.heroImages ?? [], }, ] - getHotelSuccessCounter.add(1, { hotelId, lang }) - console.info( - "api.hotels.hotel success", - JSON.stringify({ - query: { hotelId, params: params }, - }) - ) return { hotelName: hotelAttributes.name, hotelDescription: hotelAttributes.hotelContent.texts.descriptions.short,