Improve validation by applying refactor
This commit is contained in:
parent
5c1b1e3214
commit
153a792fcb
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user