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