diff --git a/utils/utils.js b/utils/utils.js index d117690..8643f3f 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -1,26 +1,26 @@ class Utils { static makeVehiclesSearchQuery(queryParams, email) { - const { - query, - brand, - model, - color, - regions, - fromDate, - toDate, - addedBy, - fromDateUpdated, - toDateUpdated, + const { + query, + brand, + model, + color, + regions, + fromDate, + toDate, + addedBy, + fromDateUpdated, + toDateUpdated, fromLocationDate, toLocationDate, year, scope } = queryParams; - - let numberQuery = Utils.makeNumberQuery(scope, query, regions?.split(',') ?? []); - let findQuery = { - 'brand.name.normalized': brand, - 'model.name.normalized': model, + + let numberQuery = Utils.makeNumberQuery(scope, query.toUpperCase(), regions?.split(',') ?? []); + let findQuery = { + 'brand.name.normalized': brand, + 'model.name.normalized': model, color }; @@ -71,11 +71,11 @@ class Utils { findQuery.addedBy = { $ne: email }; } } - + let findQueryFiltered = Object.fromEntries(Object.entries(findQuery).filter(([,val]) => val )); return { ...findQueryFiltered, ...numberQuery }; } - + static makeNumberQuery(scope, number, regions) { let mainQuery = { number: { $regex: number } }; @@ -113,7 +113,7 @@ class Utils { if(to) { conditions.push({ $lte: to }); } - + return { $and: conditions }; } @@ -148,4 +148,4 @@ class Utils { } } -export default Utils; \ No newline at end of file +export default Utils;