Improve validation by applying refactor

This commit is contained in:
Daniel García Aubert 2017-12-18 14:31:53 +01:00
parent 153a792fcb
commit e81a16ce0d

View File

@ -5,9 +5,7 @@ module.exports = class AggregationMapConfig extends MapConfig {
constructor (config, datasource) {
super(config, datasource);
aggregationValidator(this)('resolution', createNumberValidator(this));
aggregationValidator(this)('placement', createIncludesValueValidator(this, Aggregation.PLACEMENTS));
aggregationValidator(this)('threshold', createNumberValidator(this));
this.validate();
}
isAggregationMapConfig () {
@ -51,16 +49,12 @@ module.exports = class AggregationMapConfig extends MapConfig {
return aggregation;
}
validateProperty (prop, validator) {
for (let index = 0; index < this.getLayers().length; index++) {
const aggregation = this.getAggregation(index);
validate () {
const validator = aggregationValidator(this);
if (aggregation === undefined || aggregation[prop] === undefined) {
continue;
}
validator(aggregation[prop], prop, index);
}
validator('resolution', createNumberValidator(this));
validator('placement', createIncludesValueValidator(this, Aggregation.PLACEMENTS));
validator('threshold', createNumberValidator(this));
}
};