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( edges: z.array(
z.object({ z.object({
node: 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( edges: z.array(
z.object({ z.object({
node: 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 } return { spaPage, activitiesCards }
}), }),
faq: hotelFaqSchema.nullable(), faq: hotelFaqSchema.nullable(),
hotel_page_id: z.string(), hotel_page_id: z.string().transform((id) => id.trim()),
title: z.string(), title: z.string(),
url: z.string(), url: z.string(),
campaigns: z campaigns: z
@@ -148,7 +148,7 @@ export const hotelPageUrlsSchema = z
z z
.object({ .object({
url: z.string(), url: z.string(),
hotel_page_id: z.string(), hotel_page_id: z.string().transform((id) => id.trim()),
system: systemSchema, system: systemSchema,
}) })
.transform((data) => { .transform((data) => {

View File

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

View File

@@ -6,13 +6,13 @@ import { Country } from "../../../../types/country"
export const locationFilterSchema = z export const locationFilterSchema = z
.object({ .object({
country: z.nativeEnum(Country).nullable(), country: z.nativeEnum(Country).nullable(),
city_denmark: z.string().optional().nullable(), city_denmark: z.string().nullish(),
city_finland: z.string().optional().nullable(), city_finland: z.string().nullish(),
city_germany: z.string().optional().nullable(), city_germany: z.string().nullish(),
city_poland: z.string().optional().nullable(), city_poland: z.string().nullish(),
city_norway: z.string().optional().nullable(), city_norway: z.string().nullish(),
city_sweden: z.string().optional().nullable(), city_sweden: z.string().nullish(),
excluded: z.array(z.string()), excluded: z.array(z.string().transform((id) => id.trim())),
}) })
.transform((data) => { .transform((data) => {
const cities = [ const cities = [
@@ -46,7 +46,7 @@ export const contentPageHotelListingSchema = z.object({
location_filter: locationFilterSchema, location_filter: locationFilterSchema,
manual_filter: z manual_filter: z
.object({ .object({
hotels: z.array(z.string()), hotels: z.array(z.string().transform((id) => id.trim())),
}) })
.transform((data) => ({ hotels: data.hotels.filter(Boolean) })), .transform((data) => ({ hotels: data.hotels.filter(Boolean) })),
content_type: z.enum(["hotel", "restaurant", "meeting"]), content_type: z.enum(["hotel", "restaurant", "meeting"]),
@@ -82,7 +82,7 @@ export const campaignOverviewPageHotelListingSchema = z.object({
edges: z.array( edges: z.array(
z.object({ z.object({
node: 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( export const getHotel = cache(
async (input: HotelInput, serviceToken: string) => { 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 getHotelCounter = createCounter("hotel", "getHotel")
const metricsGetHotel = getHotelCounter.init({ const metricsGetHotel = getHotelCounter.init({
@@ -572,7 +573,7 @@ export const getHotel = cache(
const cacheClient = await getCacheClient() const cacheClient = await getCacheClient()
const result = await cacheClient.cacheOrGet( const result = await cacheClient.cacheOrGet(
`${input.language}:hotel:${input.hotelId}:${!!input.isCardOnlyPayment}`, `${language}:hotel:${hotelId}:${!!isCardOnlyPayment}`,
async () => { async () => {
/** /**
* Since API expects the params appended and not just * Since API expects the params appended and not just