Windshaft-cartodb/lib/api/middlewares/layer-stats.js

29 lines
837 B
JavaScript
Raw Normal View History

'use strict';
2018-03-28 19:31:37 +08:00
module.exports = function setLayerStats (pgConnection, statsBackend) {
2019-10-22 01:07:24 +08:00
return function setLayerStatsMiddleware (req, res, next) {
2018-03-28 19:31:37 +08:00
const { user, mapConfig } = res.locals;
const layergroup = res.body;
pgConnection.getConnection(user, (err, connection) => {
if (err) {
return next(err);
}
2019-10-22 01:07:24 +08:00
statsBackend.getStats(mapConfig, connection, function (err, layersStats) {
2018-03-28 19:31:37 +08:00
if (err) {
return next(err);
}
if (layersStats.length > 0) {
layergroup.metadata.layers.forEach(function (layer, index) {
layer.meta.stats = layersStats[index];
});
}
next();
});
});
};
};