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