Reduce complexity by extracting validation condition to its function
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user