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;