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:
@@ -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
|
||||
}),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user