From 19063da08ade2c4fb8df154a15437b0e189120ab Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Mon, 1 Sep 2025 07:52:53 +0000 Subject: [PATCH] feat(SW-3040): Sorting hotel listing when all hotels from a city/country are chosen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Approved-by: Matilda Landström --- packages/trpc/lib/routers/hotels/query.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/trpc/lib/routers/hotels/query.ts b/packages/trpc/lib/routers/hotels/query.ts index 67381757e..a74b87acb 100644 --- a/packages/trpc/lib/routers/hotels/query.ts +++ b/packages/trpc/lib/routers/hotels/query.ts @@ -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 }), }),