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 }), }),