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