feat(SW-3040): Sorting hotel listing when all hotels from a city/country are chosen

Approved-by: Matilda Landström
This commit is contained in:
Erik Tiekstra
2025-09-01 07:52:53 +00:00
parent ec66a5647a
commit 19063da08a

View File

@@ -595,6 +595,7 @@ export const hotelQueryRouter = router({
.input(getHotelsByCSFilterInput)
.query(async function ({ ctx, input }) {
const { locationFilter, hotelsToInclude, contentType } = input
let shouldSortByDistance = true
const language = ctx.lang
let hotelsToFetch: string[] = []
@@ -612,6 +613,7 @@ export const hotelQueryRouter = router({
if (hotelsToInclude.length) {
hotelsToFetch = hotelsToInclude
shouldSortByDistance = false
} else if (locationFilter?.city) {
const locations = await getLocations({
lang: language,
@@ -702,6 +704,14 @@ export const hotelQueryRouter = router({
metricsGetHotelsByCSFilter.success()
if (shouldSortByDistance) {
hotels.sort(
(a, b) =>
a.hotel.location.distanceToCentre -
b.hotel.location.distanceToCentre
)
}
return hotels
}),
}),