Merged in feat/SW-1418-destination-page-map-data (pull request #1347)
feat/SW-1418 destination page map data * feat(SW-1418): implement dynamic map on overview page * feat(SW-1418): update folder structure * feat(SW-1418): use getHotelsByHotelIds Approved-by: Erik Tiekstra Approved-by: Matilda Landström
This commit is contained in:
@@ -1172,6 +1172,52 @@ export const hotelQueryRouter = router({
|
||||
return hotels.filter((hotel): hotel is HotelDataWithUrl => !!hotel)
|
||||
}),
|
||||
}),
|
||||
getAllHotels: router({
|
||||
get: serviceProcedure.query(async function ({ ctx }) {
|
||||
const apiLang = toApiLang(ctx.lang)
|
||||
const params = new URLSearchParams({
|
||||
language: apiLang,
|
||||
})
|
||||
const options: RequestOptionsWithOutBody = {
|
||||
// needs to clear default option as only
|
||||
// cache or next.revalidate is permitted
|
||||
cache: undefined,
|
||||
headers: {
|
||||
Authorization: `Bearer ${ctx.serviceToken}`,
|
||||
},
|
||||
next: {
|
||||
revalidate: env.CACHE_TIME_HOTELS,
|
||||
},
|
||||
}
|
||||
const countries = await getCountries(options, params, ctx.lang)
|
||||
if (!countries) {
|
||||
return null
|
||||
}
|
||||
const countryNames = countries.data.map((country) => country.name)
|
||||
const hotelData: HotelDataWithUrl[] = (
|
||||
await Promise.all(
|
||||
countryNames.map(async (country) => {
|
||||
const countryParams = new URLSearchParams({
|
||||
country: country,
|
||||
})
|
||||
const hotelIds = await getHotelIdsByCountry(
|
||||
country,
|
||||
options,
|
||||
countryParams
|
||||
)
|
||||
|
||||
const hotels = await getHotelsByHotelIds(
|
||||
hotelIds,
|
||||
ctx.lang,
|
||||
ctx.serviceToken
|
||||
)
|
||||
return hotels
|
||||
})
|
||||
)
|
||||
).flat()
|
||||
return hotelData
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
nearbyHotelIds: serviceProcedure
|
||||
.input(nearbyHotelIdsInput)
|
||||
|
||||
@@ -348,7 +348,7 @@ export async function getHotelIdsByCityId(
|
||||
}
|
||||
|
||||
export async function getHotelIdsByCountry(
|
||||
country: Country,
|
||||
country: string,
|
||||
options: RequestOptionsWithOutBody,
|
||||
params: URLSearchParams
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user