From 3b1a86f393cd9d63338161e60ad641a506669070 Mon Sep 17 00:00:00 2001 From: Selim Mustafaev Date: Fri, 30 Sep 2022 20:50:59 +0300 Subject: [PATCH] Search by location dates --- utils/utils.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/utils/utils.js b/utils/utils.js index e1ddf30..2004167 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -1,6 +1,20 @@ class Utils { static makeVehiclesSearchQuery(queryParams, email) { - const { query, brand, model, color, regions, fromDate, toDate, addedBy, fromDateUpdated, toDateUpdated, year } = queryParams; + const { + query, + brand, + model, + color, + regions, + fromDate, + toDate, + addedBy, + fromDateUpdated, + toDateUpdated, + fromLocationDate, + toLocationDate, + year + } = queryParams; let numberQuery = Utils.makeNumberQuery(query, regions?.split(',') ?? []); let findQuery = { @@ -33,6 +47,22 @@ class Utils { } } + if(fromLocationDate || toLocationDate) { + let comparator = {}; + if(fromLocationDate) { + comparator.$gte = parseFloat(fromLocationDate); + } + if(toLocationDate) { + comparator.$lte = parseFloat(toLocationDate); + } + + findQuery.events = { + $elemMatch: { + date: comparator + } + }; + } + if(addedBy) { if(addedBy == 'me') { findQuery.addedBy = email;