Fix: Undefined dot notation in matchKeyInQuery (#5917)

* Fix: Undefined dot notation in matchKeyInQuery

* fix test

* fix postgres test

* improve tests

* FINAL test
This commit is contained in:
Diamond Lewis
2019-08-13 23:34:46 -05:00
committed by Antonio Davi Macedo Coelho de Castro
parent 470bb238b5
commit 1a7f64d8d9
3 changed files with 76 additions and 3 deletions

View File

@@ -455,10 +455,18 @@ RestQuery.prototype.replaceNotInQuery = function() {
});
};
// Used to get the deepest object from json using dot notation.
const getDeepestObjectFromKey = (json, key, idx, src) => {
if (key in json) {
return json[key];
}
src.splice(1); // Exit Early
};
const transformSelect = (selectObject, key, objects) => {
var values = [];
for (var result of objects) {
values.push(key.split('.').reduce((o, i) => o[i], result));
values.push(key.split('.').reduce(getDeepestObjectFromKey, result));
}
delete selectObject['$select'];
if (Array.isArray(selectObject['$in'])) {
@@ -523,7 +531,7 @@ RestQuery.prototype.replaceSelect = function() {
const transformDontSelect = (dontSelectObject, key, objects) => {
var values = [];
for (var result of objects) {
values.push(key.split('.').reduce((o, i) => o[i], result));
values.push(key.split('.').reduce(getDeepestObjectFromKey, result));
}
delete dontSelectObject['$dontSelect'];
if (Array.isArray(dontSelectObject['$nin'])) {