fix(SW-1446): use existing functions for url data
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
query GetLocationsUrls($locale: String!) {
|
||||
hotels: all_hotel_page(locale: $locale) {
|
||||
items {
|
||||
url
|
||||
id: hotel_page_id
|
||||
}
|
||||
}
|
||||
cities: all_destination_city_page {
|
||||
items {
|
||||
url
|
||||
id: destination_settings {
|
||||
sv: city_sweden
|
||||
pl: city_poland
|
||||
no: city_norway
|
||||
de: city_germany
|
||||
fi: city_finland
|
||||
da: city_denmark
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -301,13 +301,13 @@ export const getJumpToData = cache(async function getMemoizedJumpToData() {
|
||||
if (isCity) {
|
||||
url = urls.cities.find(
|
||||
(c) =>
|
||||
c.id &&
|
||||
c.city &&
|
||||
location.cityIdentifier &&
|
||||
c.id === location.cityIdentifier
|
||||
c.city === location.cityIdentifier
|
||||
)?.url
|
||||
} else if (isHotel) {
|
||||
url = urls.hotels.find(
|
||||
(h) => h.id && location.id && h.id === location.id
|
||||
(h) => h.hotelId && location.id && h.hotelId === location.id
|
||||
)?.url
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
|
||||
import { isDefined } from "@/server/utils"
|
||||
|
||||
import { removeMultipleSlashes } from "@/utils/url"
|
||||
|
||||
@@ -41,16 +42,16 @@ const destinationCityPageDestinationSettingsSchema = z
|
||||
city_sweden,
|
||||
location,
|
||||
}) => {
|
||||
const cities = [
|
||||
city_denmark,
|
||||
city_finland,
|
||||
city_germany,
|
||||
city_poland,
|
||||
city_norway,
|
||||
city_sweden,
|
||||
].filter((city): city is string => Boolean(city))
|
||||
|
||||
return { city: cities[0], location }
|
||||
return {
|
||||
city:
|
||||
city_denmark ||
|
||||
city_finland ||
|
||||
city_germany ||
|
||||
city_poland ||
|
||||
city_norway ||
|
||||
city_sweden,
|
||||
location,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -182,20 +183,31 @@ export const cityPageCountSchema = z
|
||||
export const cityPageUrlsSchema = z
|
||||
.object({
|
||||
all_destination_city_page: z.object({
|
||||
items: z.array(
|
||||
z
|
||||
.object({
|
||||
url: z.string(),
|
||||
destination_settings: destinationCityPageDestinationSettingsSchema,
|
||||
system: systemSchema,
|
||||
})
|
||||
.transform((data) => {
|
||||
return {
|
||||
city: data.destination_settings.city,
|
||||
url: removeMultipleSlashes(`/${data.system.locale}/${data.url}`),
|
||||
}
|
||||
})
|
||||
),
|
||||
items: z
|
||||
.array(
|
||||
z
|
||||
.object({
|
||||
url: z.string().nullish(),
|
||||
destination_settings:
|
||||
destinationCityPageDestinationSettingsSchema,
|
||||
system: systemSchema,
|
||||
})
|
||||
.transform((data) => {
|
||||
if (!data.destination_settings.city || !data.url) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
city: data.destination_settings.city,
|
||||
url: removeMultipleSlashes(
|
||||
`/${data.system.locale}/${data.url}`
|
||||
),
|
||||
}
|
||||
})
|
||||
)
|
||||
.transform((data) => {
|
||||
return data.filter(isDefined)
|
||||
}),
|
||||
}),
|
||||
})
|
||||
.transform(({ all_destination_city_page }) => all_destination_city_page.items)
|
||||
|
||||
@@ -149,6 +149,10 @@ export const destinationCityPageQueryRouter = router({
|
||||
}
|
||||
const destinationCityPage = validatedResponse.data.destination_city_page
|
||||
const cityIdentifier = destinationCityPage.destination_settings.city
|
||||
if (!cityIdentifier) {
|
||||
return null
|
||||
}
|
||||
|
||||
const city = await getCityByCityIdentifier({
|
||||
cityIdentifier,
|
||||
lang,
|
||||
|
||||
@@ -3,9 +3,8 @@ import { Lang } from "@/constants/languages"
|
||||
import { env } from "@/env/server"
|
||||
import * as api from "@/lib/api"
|
||||
import { dt } from "@/lib/dt"
|
||||
import { GetLocationsUrls } from "@/lib/graphql/Query/Locations/Locations.graphql"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import { badRequestError, unauthorizedError } from "@/server/errors/trpc"
|
||||
import { getCityPageUrls } from "@/server/routers/contentstack/destinationCityPage/utils"
|
||||
import {
|
||||
contentStackBaseWithServiceProcedure,
|
||||
publicProcedure,
|
||||
@@ -18,15 +17,10 @@ import { toApiLang } from "@/server/utils"
|
||||
import { generateChildrenString } from "@/components/HotelReservation/utils"
|
||||
import { getCacheClient } from "@/services/dataCache"
|
||||
import { cache } from "@/utils/cache"
|
||||
import { removeMultipleSlashes } from "@/utils/url"
|
||||
|
||||
import { getHotelPageUrls } from "../contentstack/hotelPage/utils"
|
||||
import { getVerifiedUser } from "../user/query"
|
||||
import { additionalDataSchema } from "./schemas/hotel/include/additionalData"
|
||||
import {
|
||||
type GetLocationsUrlsData,
|
||||
locationsUrlsSchema,
|
||||
} from "./schemas/location/urls"
|
||||
import { meetingRoomsSchema } from "./schemas/meetingRoom"
|
||||
import {
|
||||
ancillaryPackageInputSchema,
|
||||
@@ -1532,43 +1526,32 @@ export const hotelQueryRouter = router({
|
||||
JSON.stringify({ query: { lang } })
|
||||
)
|
||||
|
||||
const response = await request<GetLocationsUrlsData>(
|
||||
GetLocationsUrls,
|
||||
{ locale: lang },
|
||||
{
|
||||
key: `${lang}:${procedureName}`,
|
||||
ttl: "max",
|
||||
}
|
||||
)
|
||||
if (!response.data) {
|
||||
const [hotelPageUrlsResult, cityPageUrlsResult] =
|
||||
await Promise.allSettled([
|
||||
getHotelPageUrls(lang),
|
||||
getCityPageUrls(lang),
|
||||
])
|
||||
|
||||
if (
|
||||
hotelPageUrlsResult.status === "rejected" ||
|
||||
cityPageUrlsResult.status === "rejected"
|
||||
) {
|
||||
locationsUrlsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "no data",
|
||||
response: JSON.stringify(response),
|
||||
error_type: "no_data",
|
||||
response: JSON.stringify({
|
||||
hotelPageUrlsResult,
|
||||
cityPageUrlsResult,
|
||||
}),
|
||||
})
|
||||
|
||||
console.error(`${procedureName}: no data`, {
|
||||
variables: { lang },
|
||||
error_type: "no data",
|
||||
response,
|
||||
})
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
const locationsUrls = locationsUrlsSchema.safeParse(response.data)
|
||||
|
||||
if (!locationsUrls.success) {
|
||||
locationsUrlsFailCounter.add(1, {
|
||||
lang,
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(locationsUrls.error),
|
||||
})
|
||||
|
||||
console.error(`${procedureName}: validation error`, {
|
||||
variables: { lang },
|
||||
error_type: "validation_error",
|
||||
error: locationsUrls.error,
|
||||
error_type: "no_data",
|
||||
response: {
|
||||
hotelPageUrlsResult,
|
||||
cityPageUrlsResult,
|
||||
},
|
||||
})
|
||||
|
||||
return null
|
||||
@@ -1580,16 +1563,10 @@ export const hotelQueryRouter = router({
|
||||
variables: { lang },
|
||||
})
|
||||
|
||||
const { data } = locationsUrls
|
||||
data.hotels = data.hotels.map((hotel) => {
|
||||
hotel.url = removeMultipleSlashes(`/${lang}/${hotel.url}`)
|
||||
return hotel
|
||||
})
|
||||
data.cities = data.cities.map((city) => {
|
||||
city.url = removeMultipleSlashes(`/${lang}/${city.url}`)
|
||||
return city
|
||||
})
|
||||
return locationsUrls.data
|
||||
return {
|
||||
hotels: hotelPageUrlsResult.value,
|
||||
cities: cityPageUrlsResult.value,
|
||||
}
|
||||
}),
|
||||
}),
|
||||
map: router({
|
||||
|
||||
@@ -69,8 +69,10 @@ export function getFilteredCities(
|
||||
(hotel) => hotel.hotel.cityIdentifier
|
||||
)
|
||||
|
||||
return cities.filter((city) =>
|
||||
filteredCityIdentifiers.includes(city.destination_settings.city)
|
||||
return cities.filter(
|
||||
(city) =>
|
||||
city.destination_settings.city &&
|
||||
filteredCityIdentifiers.includes(city.destination_settings.city)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user