fix(SW-1446): use existing functions for url data
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user