diff --git a/lib/cartodb/models/aggregation/aggregation-map-config.js b/lib/cartodb/models/aggregation/aggregation-map-config.js index d2124ace..538681f7 100644 --- a/lib/cartodb/models/aggregation/aggregation-map-config.js +++ b/lib/cartodb/models/aggregation/aggregation-map-config.js @@ -5,9 +5,9 @@ module.exports = class AggregationMapConfig extends MapConfig { constructor (config, datasource) { super(config, datasource); - this.validateProperty('resolution', createNumberValidator(this)); - this.validateProperty('placement', createIncludesValueValidator(this, Aggregation.PLACEMENTS)); - this.validateProperty('threshold', createNumberValidator(this)); + aggregationValidator(this)('resolution', createNumberValidator(this)); + aggregationValidator(this)('placement', createIncludesValueValidator(this, Aggregation.PLACEMENTS)); + aggregationValidator(this)('threshold', createNumberValidator(this)); } isAggregationMapConfig () { @@ -64,6 +64,20 @@ module.exports = class AggregationMapConfig extends MapConfig { } }; +function aggregationValidator (mapconfig) { + return function validateProperty (prop, validator) { + for (let index = 0; index < mapconfig.getLayers().length; index++) { + const aggregation = mapconfig.getAggregation(index); + + if (aggregation === undefined || aggregation[prop] === undefined) { + continue; + } + + validator(aggregation[prop], prop, index); + } + }; +} + function createIncludesValueValidator(mapconfig, validValues) { return function validateIncludesValue (prop, key, index) { if (!validValues.includes(prop)) {