@synatic/mongo-magic
Advanced tools
Comparing version 0.2.5 to 0.2.6
@@ -104,2 +104,58 @@ const $merge = require('deepmerge'); | ||
} | ||
/** Merges mongo queries | ||
* | ||
* @param {string|object} fromQuery - the query to merge from | ||
* @param {string|object} toQuery - the query to merge into | ||
* @param {string} [type] - the type of merge, and/or. default is and | ||
* @returns {{$and: [any, *]}|{$and}|*|null} | ||
*/ | ||
static mergeQuery(fromQuery, toQuery, type) { | ||
if (!fromQuery && !toQuery) { | ||
return null; | ||
} else if (!fromQuery) { | ||
return toQuery; | ||
} else if (!toQuery) { | ||
return fromQuery; | ||
} | ||
if (!$check.object(fromQuery)) { | ||
try { | ||
fromQuery = JSON.parse(fromQuery); | ||
} catch (exp) { | ||
throw new Error("Invalid To Query String") | ||
} | ||
} | ||
if (!$check.object(toQuery)) { | ||
try { | ||
fromQuery = JSON.parse(toQuery); | ||
} catch (exp) { | ||
throw new Error("Invalid To Query String") | ||
} | ||
} | ||
if (type !== "or") { | ||
if (toQuery.$and) { | ||
toQuery.$and.push(fromQuery); | ||
return toQuery; | ||
} else { | ||
return { | ||
$and: [ | ||
fromQuery, | ||
toQuery | ||
] | ||
} | ||
} | ||
} else { | ||
return { | ||
$or: [ | ||
fromQuery, | ||
toQuery | ||
] | ||
} | ||
} | ||
} | ||
} | ||
@@ -106,0 +162,0 @@ |
{ | ||
"name": "@synatic/mongo-magic", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "mongo magic utils", | ||
@@ -44,3 +44,3 @@ "main": "index.js", | ||
"moment": "2.24.0", | ||
"mongodb": "3.4.0", | ||
"mongodb": "3.5.9", | ||
"odata-parser": "1.4.1", | ||
@@ -47,0 +47,0 @@ "underscore.string": "3.3.5" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20889
442
+ Addedbl@2.2.1(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddenque@1.5.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedmongodb@3.5.9(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
- Removedmongodb@3.4.0(transitive)
Updatedmongodb@3.5.9