feat(SW-2547): filter out nonActive and nonPublished hotels and cities
This commit is contained in:
committed by
Michael Zetterberg
parent
814a1c534b
commit
e38fceb237
@@ -205,7 +205,6 @@ export const destinationOverviewPageQueryRouter = router({
|
||||
lang,
|
||||
countries: countryNames,
|
||||
serviceToken: ctx.serviceToken,
|
||||
onlyPublished: true,
|
||||
})
|
||||
|
||||
const cityPages = await getCityPageUrls(lang)
|
||||
|
||||
@@ -566,6 +566,7 @@ export const getHotelIdsSchema = z
|
||||
z.object({
|
||||
attributes: z.object({
|
||||
isPublished: z.boolean(),
|
||||
isActive: z.boolean(),
|
||||
}),
|
||||
id: z.string(),
|
||||
})
|
||||
@@ -573,7 +574,7 @@ export const getHotelIdsSchema = z
|
||||
})
|
||||
.transform(({ data }) => {
|
||||
const filteredHotels = data.filter(
|
||||
(hotel) => !!hotel.attributes.isPublished
|
||||
(hotel) => !!hotel.attributes.isPublished && !!hotel.attributes.isActive
|
||||
)
|
||||
return filteredHotels.map((hotel) => hotel.id)
|
||||
})
|
||||
@@ -582,12 +583,20 @@ export const getNearbyHotelIdsSchema = z
|
||||
.object({
|
||||
data: z.array(
|
||||
z.object({
|
||||
// We only care about the hotel id
|
||||
attributes: z.object({
|
||||
isPublished: z.boolean(),
|
||||
isActive: z.boolean(),
|
||||
}),
|
||||
id: z.string(),
|
||||
})
|
||||
),
|
||||
})
|
||||
.transform((data) => data.data.map((hotel) => hotel.id))
|
||||
.transform(({ data }) => {
|
||||
const filteredHotels = data.filter(
|
||||
(hotel) => !!hotel.attributes.isPublished && !!hotel.attributes.isActive
|
||||
)
|
||||
return filteredHotels.map((hotel) => hotel.id)
|
||||
})
|
||||
|
||||
export const roomFeaturesSchema = z
|
||||
.object({
|
||||
|
||||
@@ -178,13 +178,11 @@ export async function getCountries({
|
||||
export async function getCitiesByCountry({
|
||||
countries,
|
||||
lang,
|
||||
onlyPublished = false,
|
||||
affix = locationsAffix,
|
||||
serviceToken,
|
||||
}: {
|
||||
countries: string[]
|
||||
lang: Lang
|
||||
onlyPublished?: boolean // false by default as it might be used in other places
|
||||
affix?: string
|
||||
serviceToken: string
|
||||
}): Promise<CitiesGroupedByCountry> {
|
||||
@@ -218,7 +216,6 @@ export async function getCitiesByCountry({
|
||||
console.error(citiesByCountry.error)
|
||||
throw new Error(`Unable to parse cities by country ${country}`)
|
||||
}
|
||||
|
||||
return { ...citiesByCountry.data, country }
|
||||
},
|
||||
"1d"
|
||||
@@ -228,9 +225,7 @@ export async function getCitiesByCountry({
|
||||
|
||||
const filteredCitiesByCountries = allCitiesByCountries.map((country) => ({
|
||||
...country,
|
||||
data: onlyPublished
|
||||
? country.data.filter((city) => city.isPublished)
|
||||
: country.data,
|
||||
data: country.data.filter((city) => city.isPublished),
|
||||
}))
|
||||
|
||||
const groupedCitiesByCountry: CitiesGroupedByCountry =
|
||||
|
||||
Reference in New Issue
Block a user