Extract method

This commit is contained in:
Daniel García Aubert 2017-12-01 15:43:15 +01:00
parent d01857923e
commit 0887e5d5f7

View File

@ -6,24 +6,7 @@ module.exports = class AggregationMapConfigAdapter {
return callback(null, requestMapConfig);
}
requestMapConfig.layers.forEach(layer => {
if (!this._hasLayerAggregation(layer)) {
return;
}
const aggregation = new AggregationProxy(requestMapConfig, layer.options.aggregation);
let aggregationSql = aggregation.sql();
const sqlQueryWrap = layer.options.sql_wrap;
if (sqlQueryWrap) {
layer.options.sql_raw = aggregationSql;
aggregationSql = sqlQueryWrap.replace(/<%=\s*sql\s*%>/g, aggregationSql);
}
layer.options.sql = aggregationSql;
});
requestMapConfig = this._adaptLayers(requestMapConfig);
callback(null, requestMapConfig);
}
@ -60,4 +43,25 @@ module.exports = class AggregationMapConfigAdapter {
const { aggregation } = layer.options;
return aggregation !== undefined && (typeof aggregation === 'object' && typeof aggregation === 'boolean');
}
_adaptLayers (requestMapConfig) {
return requestMapConfig.layers.map(layer => {
if (this._hasLayerAggregation(layer)) {
const aggregation = new AggregationProxy(requestMapConfig, layer.options.aggregation);
let aggregationSql = aggregation.sql();
const sqlQueryWrap = layer.options.sql_wrap;
if (sqlQueryWrap) {
layer.options.sql_raw = aggregationSql;
aggregationSql = sqlQueryWrap.replace(/<%=\s*sql\s*%>/g, aggregationSql);
}
layer.options.sql = aggregationSql;
}
return layer;
});
}
};