From c1ab601de421f3686dde2703273c006a2d45d2d1 Mon Sep 17 00:00:00 2001 From: Han Date: Thu, 11 Jul 2024 22:36:56 +0100 Subject: [PATCH] . --- src/lib/data-helpers.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib/data-helpers.js b/src/lib/data-helpers.js index b86a1e0..faddfa5 100644 --- a/src/lib/data-helpers.js +++ b/src/lib/data-helpers.js @@ -96,11 +96,16 @@ export const removeDuplicateServices = services => { } export const sortServices = (services, query) => { - let { keywords } = queryString.parse(query) + let { keywords, lat, lng, location } = queryString.parse(query) // sorting - // if there is a keyword sort by score + // if there is a location then sort by distance_away + // if there is a keyword and no location then the order matters // otherwise sort by updated_at - if (keywords) { + if (!keywords && (lat || lng || location)) { + return services.sort( + (a, b) => new Date(a.distance_away) - new Date(b.distance_away) + ) + } else if (keywords && !(lat || lng || location)) { return services.sort((a, b) => new Date(b.score) - new Date(a.score)) } else { return services.sort(