From efbed53be422b3d814fde5705e86d0c2ea2c6b52 Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Tue, 27 May 2025 11:46:59 +0000 Subject: [PATCH] fix(SW-2921): Fixed issue with countryName missing from locations response * fix(SW-2921): Added more correct cache key to locations endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Approved-by: Joakim Jäderberg Approved-by: Linus Flood --- apps/scandic-web/server/routers/hotels/output.ts | 2 +- .../server/routers/hotels/schemas/location/city.ts | 2 +- apps/scandic-web/server/routers/hotels/utils.ts | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/scandic-web/server/routers/hotels/output.ts b/apps/scandic-web/server/routers/hotels/output.ts index 893f5a56e..ff90c706c 100644 --- a/apps/scandic-web/server/routers/hotels/output.ts +++ b/apps/scandic-web/server/routers/hotels/output.ts @@ -440,7 +440,7 @@ export const locationsSchema = z.object({ if (location.type === "cities") { return { ...location.attributes, - country: location?.country ?? "", + country: location?.countryName || "", id: location.id, type: location.type, } diff --git a/apps/scandic-web/server/routers/hotels/schemas/location/city.ts b/apps/scandic-web/server/routers/hotels/schemas/location/city.ts index fe524fe16..be8753edc 100644 --- a/apps/scandic-web/server/routers/hotels/schemas/location/city.ts +++ b/apps/scandic-web/server/routers/hotels/schemas/location/city.ts @@ -7,7 +7,7 @@ export const locationCitySchema = z.object({ name: z.string().optional().default(""), isPublished: z.boolean(), }), - country: z.string().optional().default(""), + countryName: z.string().optional().default(""), id: z.string().optional().default(""), type: z.literal("cities"), }) diff --git a/apps/scandic-web/server/routers/hotels/utils.ts b/apps/scandic-web/server/routers/hotels/utils.ts index 6447f27e3..c912294ef 100644 --- a/apps/scandic-web/server/routers/hotels/utils.ts +++ b/apps/scandic-web/server/routers/hotels/utils.ts @@ -253,8 +253,15 @@ export async function getLocations({ serviceToken: string }) { const cacheClient = await getCacheClient() + const countryKeys = Object.keys(citiesByCountry ?? {}) + let cacheKey = `${lang}:locations` + + if (countryKeys.length) { + cacheKey += `:${countryKeys.join(",")}` + } + return await cacheClient.cacheOrGet( - `${lang}:locations`.toLowerCase(), + cacheKey.toLowerCase(), async () => { const params = new URLSearchParams({ language: toApiLang(lang),