From 8051dc5110074d399b31331a4882b33bff2ff0a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 11 Mar 2019 17:14:07 +0100 Subject: [PATCH] Reduce complexity by extracting validation condition to its function --- lib/cartodb/backends/cluster.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/cartodb/backends/cluster.js b/lib/cartodb/backends/cluster.js index 8ad2343c..e305eb28 100644 --- a/lib/cartodb/backends/cluster.js +++ b/lib/cartodb/backends/cluster.js @@ -7,7 +7,7 @@ const AggregationMapConfig = require('../models/aggregation/aggregation-mapconfi module.exports = class ClusterBackend { // TODO: reduce complexity - // jshint maxcomplexity: 15 + // jshint maxcomplexity: 13 getClusterFeatures (mapConfigProvider, params, callback) { mapConfigProvider.getMapConfig((err, _mapConfig) => { if (err) { @@ -77,9 +77,7 @@ module.exports = class ClusterBackend { } if (expressions !== undefined) { - if (expressions === null || - Array.isArray(expressions) || - ['string', 'number', 'boolean'].includes(typeof expressions)) { + if (!isValidExpression(expressions)) { const error = new Error( `Invalid aggregation input, expressions should be and object with valid functions` ); @@ -265,3 +263,9 @@ function hasAggregationLayer (mapConfig, layerIndex) { function hasColumns (columns) { return Array.isArray(columns) && columns.length; } + +function isValidExpression (expressions) { + const invalidTypes = ['string', 'number', 'boolean']; + + return expressions !== null && !Array.isArray(expressions) && !invalidTypes.includes(typeof expressions); +}