Refactor supported geometry types

This commit is contained in:
Daniel García Aubert
2017-12-18 18:53:44 +01:00
parent 47e4b9da0d
commit 6638ba91c3
2 changed files with 15 additions and 7 deletions
@@ -22,6 +22,16 @@ module.exports = class AggregationMapConfig extends MapConfig {
return 1;
}
static get SUPPORTED_GEOMETRY_TYPES () {
return [
'ST_Point'
];
}
static supportsGeometryType(geometryType) {
return AggregationMapConfig.SUPPORTED_GEOMETRY_TYPES.includes(geometryType);
}
constructor (config, datasource) {
super(config, datasource);
@@ -2,7 +2,8 @@ const AggregationMapConfig = require('../../aggregation/aggregation-map-config')
const queryUtils = require('../../../utils/query-utils');
const unsupportedGeometryTypeErrorMessage = ctx =>
`Unsupported geometry type: ${ctx.geometryType}. Aggregation is available only for geometry type: ST_Point`;
`Unsupported geometry type: ${ctx.geometryType}. ` +
`Aggregation is available only for geometry type: ${AggregationMapConfig.SUPPORTED_GEOMETRY_TYPES}`;
const invalidAggregationParamValueErrorMessage = ctx =>
`Invalid value for 'aggregation' query param: ${ctx.value}. Valid ones are 'true' or 'false'`;
@@ -116,16 +117,13 @@ module.exports = class AggregationMapConfigAdapter {
}
const result = res.rows[0] || {};
const estimatedFeatureCount = result.count;
if (!mapConfig.doesLayerReachThreshold(index, estimatedFeatureCount)) {
if (!mapConfig.doesLayerReachThreshold(index, result.count)) {
return callback(null, shouldAdapt);
}
const geometryType = result.type;
if (geometryType !== 'ST_Point') {
return callback(new Error(unsupportedGeometryTypeErrorMessage({ geometryType })));
if (!AggregationMapConfig.supportsGeometryType(result.type)) {
return callback(new Error(unsupportedGeometryTypeErrorMessage({ geometryType: result.type })));
}
shouldAdapt = true;