Extract incrementMapViews middleware from controllers middleware

This commit is contained in:
Daniel García Aubert
2018-03-14 13:18:37 +01:00
parent 3b3e0c0acd
commit 2d4ce19250
+5 -5
View File
@@ -83,7 +83,7 @@ NamedMapsController.prototype.register = function(app) {
prepareLayerFilterFromPreviewLayers(staticOptions),
getStaticImageOptions({ tablesExtentApi: this.tablesExtentApi }),
getImage(staticOptions),
this.incrementMapViews(),
incrementMapViews({ metadataBackend: this.metadataBackend }),
this.setSurrogateKey(),
this.setCacheChannelHeader(),
this.setLastModifiedHeader(),
@@ -366,7 +366,7 @@ function incrementMapViewsError (ctx) {
return `ERROR: failed to increment mapview count for user '${ctx.user}': ${ctx.err}`;
}
NamedMapsController.prototype.incrementMapViews = function () {
function incrementMapViews ({ metadataBackend }) {
return function incrementMapViewsMiddleware(req, res, next) {
const { user, namedMapProvider } = res.locals;
@@ -378,7 +378,7 @@ NamedMapsController.prototype.incrementMapViews = function () {
const statTag = mapConfig.obj().stat_tag;
this.metadataBackend.incMapviewCount(user, statTag, (err) => {
metadataBackend.incMapviewCount(user, statTag, (err) => {
if (err) {
global.logger.log(incrementMapViewsError({ user, err }));
}
@@ -386,8 +386,8 @@ NamedMapsController.prototype.incrementMapViews = function () {
next();
});
});
}.bind(this);
};
};
}
function templateZoomCenter(view) {
if (view.zoom !== undefined && view.center) {