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