nodester 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/query/traverse.js +16 -13
- package/package.json +1 -1
package/lib/query/traverse.js
CHANGED
|
@@ -171,6 +171,7 @@ function traverse(queryNode, filter=null, model=null) {
|
|
|
171
171
|
|
|
172
172
|
const clausesEntries = Object.entries(clauses);
|
|
173
173
|
for (let [clauseName, value] of clausesEntries) {
|
|
174
|
+
|
|
174
175
|
// If clause is not available:
|
|
175
176
|
if (filter != null) {
|
|
176
177
|
if (filter.clauses.indexOf(clauseName) === -1)
|
|
@@ -270,7 +271,7 @@ function traverse(queryNode, filter=null, model=null) {
|
|
|
270
271
|
|
|
271
272
|
case null:
|
|
272
273
|
case undefined:
|
|
273
|
-
newQuery.order = [ ['id', 'desc'] ];
|
|
274
|
+
// newQuery.order = [ ['id', 'desc'] ];
|
|
274
275
|
break;
|
|
275
276
|
|
|
276
277
|
default:
|
|
@@ -298,13 +299,22 @@ function traverse(queryNode, filter=null, model=null) {
|
|
|
298
299
|
|
|
299
300
|
|
|
300
301
|
// Where:
|
|
302
|
+
|
|
303
|
+
// Set aatributes from Query:
|
|
301
304
|
const whereEntries = Object.entries(where);
|
|
302
|
-
for (let [attribute, value] of whereEntries) {
|
|
303
|
-
_parseWhereEntry(attribute, value, newQuery.where
|
|
305
|
+
for (let [ attribute, value ] of whereEntries) {
|
|
306
|
+
_parseWhereEntry(attribute, value, newQuery.where);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Static attributes override previously set attributes:
|
|
310
|
+
const staticAttributesEntries = Object.entries(filter.statics.attributes);
|
|
311
|
+
for (let [ attribute, staticValue ] of staticAttributesEntries) {
|
|
312
|
+
newQuery.where[attribute] = _parseValue(staticValue, attribute);
|
|
304
313
|
}
|
|
305
314
|
|
|
306
|
-
//
|
|
307
|
-
|
|
315
|
+
// If "where" was not set in any way,
|
|
316
|
+
// remove it from the db query:
|
|
317
|
+
if (Object.entries(newQuery.where).length === 0) {
|
|
308
318
|
delete newQuery.where;
|
|
309
319
|
}
|
|
310
320
|
// Where\
|
|
@@ -360,9 +370,8 @@ function _addAssociationQuery(associationQuery, includeName, resultQuery) {
|
|
|
360
370
|
}
|
|
361
371
|
|
|
362
372
|
|
|
363
|
-
function _parseWhereEntry(attribute, value, whereHolder
|
|
373
|
+
function _parseWhereEntry(attribute, value, whereHolder) {
|
|
364
374
|
let _value = value;
|
|
365
|
-
const staticAttribute = staticAttributes[attribute];
|
|
366
375
|
|
|
367
376
|
// If attribute is Op (not, like, or, etc.):
|
|
368
377
|
if (attribute in Op) {
|
|
@@ -373,12 +382,6 @@ function _parseWhereEntry(attribute, value, whereHolder, staticAttributes) {
|
|
|
373
382
|
whereHolder[op] = _value;
|
|
374
383
|
return;
|
|
375
384
|
}
|
|
376
|
-
|
|
377
|
-
// Static value overrides any other:
|
|
378
|
-
if (!!staticAttribute) {
|
|
379
|
-
whereHolder[attribute] = staticAttribute;
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
385
|
|
|
383
386
|
whereHolder[attribute] = _parseValue(_value, attribute);
|
|
384
387
|
}
|