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:
Fredrik Thorsson
2025-02-17 08:59:50 +00:00
parent f5c5172555
commit 22111eb7d2
24 changed files with 123 additions and 141 deletions

View File

@@ -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)

View File

@@ -348,7 +348,7 @@ export async function getHotelIdsByCityId(
}
export async function getHotelIdsByCountry(
country: Country,
country: string,
options: RequestOptionsWithOutBody,
params: URLSearchParams
) {