Merged in feat/SW-1333-hotel-endpoint (pull request #1206)

Feat(SW-133): Add additionalData endpoint

Approved-by: Erik Tiekstra
Approved-by: Fredrik Thorsson
This commit is contained in:
Matilda Landström
2025-01-27 11:39:13 +00:00
parent bf76c6277f
commit 577a4ca35e
17 changed files with 239 additions and 50 deletions

View File

@@ -5,7 +5,7 @@ export function getTypeSpecificInformation(
contentType: HotelListing["contentType"],
hotel: Hotel
) {
const { restaurantsOverviewPage, images } = hotel.hotelContent
const { images } = hotel.hotelContent
const { descriptions, meetingDescription } = hotel.hotelContent.texts
const hotelData = {
description: descriptions.short,
@@ -24,8 +24,8 @@ export function getTypeSpecificInformation(
const restaurantImage = hotel.restaurantImages?.heroImages[0]
return {
description:
restaurantsOverviewPage.restaurantsContentDescriptionShort ||
hotelData.description,
hotel.hotelContent.restaurantsOverviewPage
.restaurantsContentDescriptionShort || hotelData.description,
imageSrc: restaurantImage?.imageSizes.small || hotelData.imageSrc,
altText: restaurantImage?.metaData.altText || hotelData.altText,
}

View File

@@ -41,7 +41,7 @@ import styles from "./hotelPage.module.css"
import { FacilityCardTypeEnum } from "@/types/components/hotelPage/facilities"
import type { HotelPageProps } from "@/types/components/hotelPage/hotelPage"
import { HotelHashValues } from "@/types/components/hotelPage/tabNavigation"
import type { Facility } from "@/types/hotel"
import type { AdditionalData, Facility } from "@/types/hotel"
import { PageContentTypeEnum } from "@/types/requests/contentType"
export default async function HotelPage({ hotelId }: HotelPageProps) {
@@ -63,12 +63,7 @@ export default async function HotelPage({ hotelId }: HotelPageProps) {
name,
address,
pointsOfInterest,
gallery,
specialAlerts,
healthAndWellness,
restaurantImages,
conferencesAndMeetings,
hotelRoomElevatorPitchText,
hotelContent,
detailedFacilities,
healthFacilities,
@@ -79,8 +74,18 @@ export default async function HotelPage({ hotelId }: HotelPageProps) {
ratings,
parking,
} = hotelData.data.attributes
const roomCategories = hotelData.included?.rooms || []
const restaurants = hotelData.included?.restaurants || []
const roomCategories = hotelData.included.rooms || []
const restaurants = hotelData.included.restaurants || []
const additionalData =
hotelData.included.additionalData || ({} as AdditionalData)
const {
healthAndWellness,
restaurantImages,
conferencesAndMeetings,
hotelRoomElevatorPitchText,
gallery,
} = additionalData
const images = gallery?.smallerImages
const description = hotelContent.texts.descriptions.medium

View File

@@ -95,7 +95,7 @@ export async function RoomsContainer({
<Rooms
availablePackages={packages ?? []}
roomsAvailability={roomsAvailability}
roomCategories={hotelData?.included?.rooms ?? []}
roomCategories={hotelData?.included.rooms ?? []}
hotelType={hotelData?.data.attributes?.hotelType}
isUserLoggedIn={isUserLoggedIn}
/>

View File

@@ -32,7 +32,7 @@ export default function HotelReservationSidePeek({
}
)
const selectedRoom = hotelData?.included?.rooms?.find((room) =>
const selectedRoom = hotelData?.included.rooms?.find((room) =>
room.roomTypes.some((type) => type.code === roomTypeCode)
)
@@ -42,6 +42,7 @@ export default function HotelReservationSidePeek({
{hotelData && (
<HotelSidePeek
hotel={hotelData.data?.attributes}
additionalHotelData={hotelData.included.additionalData}
activeSidePeek={activeSidePeek}
close={close}
showCTA={showCTA}

View File

@@ -4,7 +4,6 @@ import { mapFacilityToIcon } from "@/components/ContentType/HotelPage/data"
import Contact from "@/components/HotelReservation/Contact"
import Accordion from "@/components/TempDesignSystem/Accordion"
import SidePeek from "@/components/TempDesignSystem/SidePeek"
import Body from "@/components/TempDesignSystem/Text/Body"
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
import Accessibility from "./Accordions/Accessibility"
@@ -20,6 +19,7 @@ import { SidePeekEnum } from "@/types/components/hotelReservation/sidePeek"
export default function HotelSidePeek({
hotel,
additionalHotelData,
activeSidePeek,
close,
showCTA,
@@ -45,19 +45,19 @@ export default function HotelSidePeek({
<Contact hotel={hotel} />
<Accordion>
{parking?.length > 0 && <Parking parking={parking} />}
{hotel.hotelContent?.restaurantsOverviewPage
{additionalHotelData?.restaurantsOverviewPage
?.restaurantsContentDescriptionMedium && (
<Restaurant
restaurantsContentDescriptionMedium={
hotel.hotelContent.restaurantsOverviewPage
additionalHotelData.restaurantsOverviewPage
.restaurantsContentDescriptionMedium
}
/>
)}
{hotel?.accessibilityElevatorPitchText && (
{additionalHotelData?.accessibilityElevatorPitchText && (
<Accessibility
accessibilityElevatorPitchText={
hotel.accessibilityElevatorPitchText
additionalHotelData.accessibilityElevatorPitchText
}
/>
)}

View File

@@ -114,6 +114,9 @@ export namespace endpoints {
export function roomCategories(hotelId: string) {
return `${hotels}/${hotelId}/roomCategories`
}
export function additionalData(hotelId: string) {
return `${hotels}/${hotelId}/additionalData`
}
}
export const locations = `${base.path.hotel}/${version}/${base.enitity.Locations}`

View File

@@ -171,6 +171,15 @@ export const getMeetingRooms = cache(
}
)
export const getAdditionalData = cache(
async function getMemoizedAdditionalData(input: {
hotelId: string
language: Lang
}) {
return serverClient().hotel.additionalData(input)
}
)
export const getDestinationOverviewPage = cache(
async function getMemoizedDestinationOverviewPage() {
return serverClient().contentstack.destinationOverviewPage.get()

View File

@@ -146,7 +146,7 @@ export const bookingQueryRouter = router({
included: hotelData.included,
},
room: getBookedHotelRoom(
hotelData.included?.rooms,
hotelData.included.rooms,
booking.data.roomTypeCode
),
}

View File

@@ -98,3 +98,8 @@ export const getMeetingRoomsInputSchema = z.object({
hotelId: z.string(),
language: z.string(),
})
export const getAdditionalDataInputSchema = z.object({
hotelId: z.string(),
language: z.string(),
})

View File

@@ -3,6 +3,7 @@ import { z } from "zod"
import { ChildBedTypeEnum, type PaymentMethodEnum } from "@/constants/booking"
import { toLang } from "@/server/utils"
import { additionalDataSchema } from "./schemas/additionalData"
import { imageSchema } from "./schemas/image"
import { restaurantSchema } from "./schemas/restaurants"
import { roomSchema } from "./schemas/room"
@@ -12,7 +13,7 @@ import { getPoiGroupByCategoryName } from "./utils"
import { RoomPackageCodeEnum } from "@/types/components/hotelReservation/selectRate/roomFilter"
import { FacilityEnum } from "@/types/enums/facilities"
import { PackageTypeEnum } from "@/types/enums/packages"
import type { RestaurantData, RoomData } from "@/types/hotel"
import type { AdditionalData, RestaurantData, RoomData } from "@/types/hotel"
const ratingsSchema = z
.object({
@@ -119,7 +120,7 @@ const hotelContentSchema = z.object({
restaurantsOverviewPageLink: z.string().optional(),
restaurantsContentDescriptionShort: z.string().optional(),
restaurantsContentDescriptionMedium: z.string().optional(),
}),
}), // TODO remove, use new /additionalData endpoint
})
const detailedFacilitySchema = z.object({
@@ -134,12 +135,12 @@ const detailedFacilitySchema = z.object({
export const facilitySchema = z.object({
headingText: z.string().default(""),
heroImages: z.array(imageSchema),
})
}) // TODO remove, use new /additionalData endpoint
export const gallerySchema = z.object({
heroImages: z.array(imageSchema),
smallerImages: z.array(imageSchema),
})
}) // TODO remove, use new /additionalData endpoint
const healthFacilitySchema = z.object({
type: z.string(),
@@ -289,16 +290,6 @@ export const parkingSchema = z.object({
pricing: parkingPricingSchema,
})
const specialNeedSchema = z.object({
name: z.string(),
details: z.string(),
})
const specialNeedGroupSchema = z.object({
name: z.string(),
specialNeeds: z.array(specialNeedSchema),
})
const socialMediaSchema = z.object({
instagram: z.string().optional(),
facebook: z.string().optional(),
@@ -392,11 +383,10 @@ type DetailedFacility = { id: FacilityEnum } & z.infer<
typeof detailedFacilitySchema
>
export const hotelAttributesSchema = z.object({
accessibilityElevatorPitchText: z.string().optional(),
address: addressSchema,
cityId: z.string(),
cityName: z.string(),
conferencesAndMeetings: facilitySchema.optional(),
conferencesAndMeetings: facilitySchema.optional(), // TODO remove, use new /additionalData endpoint
contactInformation: contactInformationSchema,
detailedFacilities: z.array(detailedFacilitySchema).transform(
(facilities) =>
@@ -407,13 +397,11 @@ export const hotelAttributesSchema = z.object({
)
.sort((a, b) => b.sortOrder - a.sortOrder) as DetailedFacility[]
),
gallery: gallerySchema.optional(),
gallery: gallerySchema.optional(), // TODO remove, use new /additionalData endpoint
galleryImages: z.array(imageSchema).optional(),
healthAndWellness: facilitySchema.optional(),
healthFacilities: z.array(healthFacilitySchema),
hotelContent: hotelContentSchema,
hotelFacts: hotelFactsSchema,
hotelRoomElevatorPitchText: z.string().optional(),
hotelType: z.string().optional(),
isActive: z.boolean(),
isPublished: z.boolean(),
@@ -430,23 +418,26 @@ export const hotelAttributesSchema = z.object({
),
ratings: ratingsSchema,
rewardNight: rewardNightSchema,
restaurantImages: facilitySchema.optional(),
restaurantImages: facilitySchema.optional(), // TODO remove, use new /additionalData endpoint
socialMedia: socialMediaSchema,
specialAlerts: specialAlertsSchema,
specialNeedGroups: z.array(specialNeedGroupSchema),
vat: z.number(),
})
const includedSchema = z
.array(z.union([roomSchema, restaurantSchema]))
.array(z.union([roomSchema, restaurantSchema, additionalDataSchema]))
.transform((data) => {
const rooms = data.filter((d) => d.type === "roomcategories") as RoomData[]
const restaurants = data.filter(
(d) => d.type === "restaurants"
) as RestaurantData[]
const additionalData = data.filter(
(d) => d.type === "additionalData"
) as AdditionalData[]
return {
rooms,
restaurants,
additionalData,
}
})
@@ -467,7 +458,13 @@ export const getHotelDataSchema = z.object({
}),
// NOTE: We can pass an "include" param to the hotel API to retrieve
// additional data for an individual hotel.
included: includedSchema.optional(),
included: includedSchema.optional().transform((incl) => {
return {
restaurants: incl?.restaurants,
rooms: incl?.rooms,
additionalData: incl?.additionalData[0],
}
}),
})
export const childrenSchema = z.object({

View File

@@ -16,7 +16,9 @@ import { cache } from "@/utils/cache"
import { getHotelPageUrl } from "../contentstack/hotelPage/utils"
import { getVerifiedUser, parsedUser } from "../user/query"
import { additionalDataSchema } from "./schemas/additionalData"
import {
getAdditionalDataInputSchema,
getBreakfastPackageInputSchema,
getCityCoordinatesInputSchema,
getHotelDataInputSchema,
@@ -39,6 +41,9 @@ import {
getRoomsAvailabilitySchema,
} from "./output"
import {
additionalDataCounter,
additionalDataFailCounter,
additionalDataSuccessCounter,
breakfastPackagesCounter,
breakfastPackagesFailCounter,
breakfastPackagesSuccessCounter,
@@ -86,7 +91,7 @@ export const getHotelData = cache(
async (input: HotelDataInput, serviceToken: string) => {
const { hotelId, language, isCardOnlyPayment } = input
const includes = ["RoomCategories", "Restaurants"] // "RoomCategories","NearbyHotels","Restaurants","City",
const includes = ["RoomCategories", "Restaurants", "AdditionalData"] //"NearbyHotels","Restaurants","City",
const params = new URLSearchParams({
hotelId,
language,
@@ -182,8 +187,10 @@ export const getHotelData = cache(
hotelData.data.attributes.merchantInformationData.alternatePaymentOptions =
[]
}
if (hotelData.data.attributes.gallery) {
const smallerImages = hotelData.data.attributes.gallery.smallerImages
const gallery = hotelData.included.additionalData?.gallery
if (gallery) {
const smallerImages = gallery.smallerImages
const hotelGalleryImages =
hotelData.data.attributes.hotelType === HotelTypeEnum.Signature
? smallerImages.slice(0, 10)
@@ -604,7 +611,7 @@ export const hotelQueryRouter = router({
const bedTypes = availableRoomsInCategory
.map((availRoom) => {
const matchingRoom = hotelData?.included?.rooms
const matchingRoom = hotelData?.included.rooms
?.find((room) =>
room.roomTypes
.map((roomType) => roomType.code)
@@ -1253,4 +1260,82 @@ export const hotelQueryRouter = router({
return validatedMeetingRooms.data.data
}),
additionalData: safeProtectedServiceProcedure
.input(getAdditionalDataInputSchema)
.query(async function ({ ctx, input }) {
const { hotelId, language } = input
const params: Record<string, string | string[]> = {
hotelId,
language,
}
const metricsData = { ...params, hotelId: input.hotelId }
additionalDataCounter.add(1, metricsData)
console.info(
"api.hotels.additionalData start",
JSON.stringify({ query: { hotelId, params } })
)
const apiResponse = await api.get(
api.endpoints.v1.Hotel.Hotels.additionalData(input.hotelId),
{
cache: undefined,
headers: {
Authorization: `Bearer ${ctx.serviceToken}`,
},
next: {
revalidate: env.CACHE_TIME_HOTELS,
},
},
params
)
if (!apiResponse.ok) {
const text = await apiResponse.text()
additionalDataFailCounter.add(1, {
...metricsData,
error_type: "http_error",
error: JSON.stringify({
status: apiResponse.status,
statusText: apiResponse.statusText,
text,
}),
})
console.error(
"api.hotels.additionalData error",
JSON.stringify({
query: { params },
error: {
status: apiResponse.status,
statusText: apiResponse.statusText,
text,
},
})
)
return null
}
const apiJson = await apiResponse.json()
const validatedAdditionalData = additionalDataSchema.safeParse(apiJson)
if (!validatedAdditionalData.success) {
console.error(
"api.hotels.additionalData validation error",
JSON.stringify({
query: { params },
error: validatedAdditionalData.error,
})
)
throw badRequestError()
}
additionalDataSuccessCounter.add(1, {
hotelId,
})
console.info(
"api.hotels.additionalData success",
JSON.stringify({ query: { params } })
)
return validatedAdditionalData.data
}),
})

View File

@@ -0,0 +1,67 @@
import { z } from "zod"
import { imageSchema } from "./image"
const specialNeedSchema = z.object({
name: z.string(),
details: z.string(),
})
const specialNeedGroupSchema = z.object({
name: z.string(),
specialNeeds: z.array(specialNeedSchema),
})
export const gallerySchema = z.object({
heroImages: z.array(imageSchema),
smallerImages: z.array(imageSchema),
})
export const facilitySchema = z.object({
headingText: z.string().default(""),
heroImages: z.array(imageSchema),
})
export const restaurantsOverviewPageSchema = z.object({
restaurantsOverviewPageLinkText: z.string().optional(),
restaurantsOverviewPageLink: z.string().optional(),
restaurantsContentDescriptionShort: z.string().optional(),
restaurantsContentDescriptionMedium: z.string().optional(),
})
const extraPageSchema = z.object({
elevatorPitch: z.string().optional(),
mainBody: z.string().optional(),
})
export const additionalDataSchema = z
.object({
attributes: z.object({
name: z.string(),
id: z.string(),
displayWebPage: z.object({
healthGym: z.boolean(),
meetingRoom: z.boolean(),
parking: z.boolean(),
specialNeeds: z.boolean(),
}),
specialNeedGroups: z.array(specialNeedGroupSchema),
gallery: gallerySchema.optional(),
conferencesAndMeetings: facilitySchema.optional(),
healthAndWellness: facilitySchema.optional(),
restaurantImages: facilitySchema.optional(),
restaurantsOverviewPage: restaurantsOverviewPageSchema,
meetingRooms: extraPageSchema,
healthAndFitness: extraPageSchema,
hotelParking: extraPageSchema,
hotelSpecialNeeds: extraPageSchema,
accessibilityElevatorPitchText: z.string().optional(),
hotelRoomElevatorPitchText: z.string().optional(),
}),
type: z.literal("additionalData"),
})
.transform(({ attributes, type }) => ({
...attributes,
type,
id: attributes.id,
}))

View File

@@ -36,6 +36,7 @@ export const restaurantSchema = z
attributes: z.object({
name: z.string(),
isPublished: z.boolean().default(false),
restaurantPage: z.boolean(),
email: z.string().optional(),
phoneNumber: z.string().optional(),
externalBreakfast: z

View File

@@ -82,3 +82,13 @@ export const meetingRoomsSuccessCounter = meter.createCounter(
export const meetingRoomsFailCounter = meter.createCounter(
"trpc.hotels.meetingRooms-fail"
)
export const additionalDataCounter = meter.createCounter(
"trpc.hotels.additionalData"
)
export const additionalDataSuccessCounter = meter.createCounter(
"trpc.hotels.additionalData-success"
)
export const additionalDataFailCounter = meter.createCounter(
"trpc.hotels.additionalData-fail"
)

View File

@@ -1,8 +1,9 @@
import { SidePeekEnum } from "@/types/components/hotelReservation/sidePeek"
import { Hotel } from "@/types/hotel"
import type { SidePeekEnum } from "@/types/components/hotelReservation/sidePeek"
import type { AdditionalData, Hotel } from "@/types/hotel"
export type HotelSidePeekProps = {
hotel: Hotel
additionalHotelData: AdditionalData | undefined
activeSidePeek: SidePeekEnum
close: () => void
showCTA: boolean

View File

@@ -2,11 +2,14 @@ import type { z } from "zod"
import type {
checkinSchema,
facilitySchema,
getHotelDataSchema,
parkingSchema,
pointOfInterestSchema,
} from "@/server/routers/hotels/output"
import type {
additionalDataSchema,
facilitySchema,
} from "@/server/routers/hotels/schemas/additionalData"
import type { imageSchema } from "@/server/routers/hotels/schemas/image"
import type {
restaurantOpeningHoursSchema,
@@ -36,6 +39,8 @@ export type RestaurantOpeningHours = z.output<
export type GalleryImage = z.infer<typeof imageSchema>
export type CheckInData = z.infer<typeof checkinSchema>
export type AdditionalData = z.infer<typeof additionalDataSchema>
export type PointOfInterest = z.output<typeof pointOfInterestSchema>
export enum PointOfInterestGroupEnum {

View File

@@ -9,7 +9,7 @@ export interface BookingConfirmation {
booking: BookingConfirmationSchema
hotel: Hotel & {
included?: {
rooms: RoomData[]
rooms: RoomData[] | undefined
}
}
room: