fix: Trimming hotel ids from contentstack to avoid 404 errors when fetching hotel data

Approved-by: Linus Flood
Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-09-12 09:18:50 +00:00
parent 15a352ea99
commit ce71fc421c
5 changed files with 20 additions and 16 deletions

View File

@@ -106,7 +106,7 @@ export const includedHotelsSchema = z
edges: z.array(
z.object({
node: z.object({
hotel_page_id: z.string(),
hotel_page_id: z.string().transform((id) => id.trim()),
}),
})
),
@@ -115,7 +115,7 @@ export const includedHotelsSchema = z
edges: z.array(
z.object({
node: z.object({
hotel_page_id: z.string(),
hotel_page_id: z.string().transform((id) => id.trim()),
}),
})
),

View File

@@ -68,7 +68,7 @@ export const hotelPageSchema = z.object({
return { spaPage, activitiesCards }
}),
faq: hotelFaqSchema.nullable(),
hotel_page_id: z.string(),
hotel_page_id: z.string().transform((id) => id.trim()),
title: z.string(),
url: z.string(),
campaigns: z
@@ -148,7 +148,7 @@ export const hotelPageUrlsSchema = z
z
.object({
url: z.string(),
hotel_page_id: z.string(),
hotel_page_id: z.string().transform((id) => id.trim()),
system: systemSchema,
})
.transform((data) => {

View File

@@ -113,7 +113,10 @@ export const rawMetadataSchema = z.object({
)
.nullish(),
blocks: metaDataBlocksSchema,
hotel_page_id: z.string().nullish(),
hotel_page_id: z
.string()
.nullish()
.transform((id) => id?.trim() || null),
hotelData: hotelAttributesSchema
.pick({
name: true,

View File

@@ -6,13 +6,13 @@ import { Country } from "../../../../types/country"
export const locationFilterSchema = z
.object({
country: z.nativeEnum(Country).nullable(),
city_denmark: z.string().optional().nullable(),
city_finland: z.string().optional().nullable(),
city_germany: z.string().optional().nullable(),
city_poland: z.string().optional().nullable(),
city_norway: z.string().optional().nullable(),
city_sweden: z.string().optional().nullable(),
excluded: z.array(z.string()),
city_denmark: z.string().nullish(),
city_finland: z.string().nullish(),
city_germany: z.string().nullish(),
city_poland: z.string().nullish(),
city_norway: z.string().nullish(),
city_sweden: z.string().nullish(),
excluded: z.array(z.string().transform((id) => id.trim())),
})
.transform((data) => {
const cities = [
@@ -46,7 +46,7 @@ export const contentPageHotelListingSchema = z.object({
location_filter: locationFilterSchema,
manual_filter: z
.object({
hotels: z.array(z.string()),
hotels: z.array(z.string().transform((id) => id.trim())),
})
.transform((data) => ({ hotels: data.hotels.filter(Boolean) })),
content_type: z.enum(["hotel", "restaurant", "meeting"]),
@@ -82,7 +82,7 @@ export const campaignOverviewPageHotelListingSchema = z.object({
edges: z.array(
z.object({
node: z.object({
hotel_page_id: z.string(),
hotel_page_id: z.string().transform((id) => id.trim()),
}),
})
),

View File

@@ -558,7 +558,8 @@ export async function getLocations({
export const getHotel = cache(
async (input: HotelInput, serviceToken: string) => {
const { hotelId, language, isCardOnlyPayment } = input
const { language, isCardOnlyPayment } = input
const hotelId = input.hotelId.trim()
const getHotelCounter = createCounter("hotel", "getHotel")
const metricsGetHotel = getHotelCounter.init({
@@ -572,7 +573,7 @@ export const getHotel = cache(
const cacheClient = await getCacheClient()
const result = await cacheClient.cacheOrGet(
`${input.language}:hotel:${input.hotelId}:${!!input.isCardOnlyPayment}`,
`${language}:hotel:${hotelId}:${!!isCardOnlyPayment}`,
async () => {
/**
* Since API expects the params appended and not just