From bc0e47ee12381fe8160e30fe19f9959e53ebdc6f Mon Sep 17 00:00:00 2001 From: Mihai Dima Date: Tue, 5 Apr 2016 11:58:30 +0300 Subject: [PATCH] code cleanup --- lib/query-builder.js | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/lib/query-builder.js b/lib/query-builder.js index 6066821..e229822 100644 --- a/lib/query-builder.js +++ b/lib/query-builder.js @@ -3,7 +3,7 @@ var _ = require('lodash') var OpParser = require('./operator_parser') -module.exports = function (seneca, opts) { +module.exports = function (seneca) { var StandardQuery seneca.ready(function () { StandardQuery = seneca.export('standard-query/utils') @@ -11,44 +11,39 @@ module.exports = function (seneca, opts) { function parseExtendedExpression (sTypes, currentName, currentValue, params, values) { function parseComplexSelectOperator (sTypes, currentName, currentValue, params, values) { - var result = { - processed: false - } + var result = {} - for (var op in currentValue) { - var op_val = currentValue[op] + result.processed = _.every(currentValue, function (opVal, op) { if (!OpParser[op]) { result.err = 'This operator is not yet implemented: ' + op - return result + return false } - var err = OpParser[op](currentName, op_val, params, values, sTypes) + var err = OpParser[op](currentName, opVal, params, values, sTypes) if (err) { result.err = err - return result + return false } - result.processed = true - } + return true + }) return result } var result = StandardQuery.parseExpression(sTypes, currentName, currentValue, params, values) - if (!result.processed) { - if (_.isObject(currentValue)) { - result = parseComplexSelectOperator(sTypes, currentName, currentValue, params, values) - if (result.err) { - return result - } + if (!result.processed && _.isObject(currentValue)) { + result = parseComplexSelectOperator(sTypes, currentName, currentValue, params, values) + if (result.err) { + return result } } return result } - function buildQueryFromExpression (entp, query_parameters, sTypes, values) { - return StandardQuery.buildQueryFromExpressionCustom(entp, query_parameters, sTypes, values, parseExtendedExpression) + function buildQueryFromExpression (entp, queryParameters, sTypes, values) { + return StandardQuery.buildQueryFromExpressionCustom(entp, queryParameters, sTypes, values, parseExtendedExpression) } function selectstm (qent, q, sTypes, done) {