Extract incrementMapViews middleware from controllers middleware
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user