Middlewarify search dataview endpoint

This commit is contained in:
Daniel García Aubert 2018-03-05 18:05:42 +01:00
parent acb9ce33b1
commit 40712a2e62

View File

@ -144,7 +144,8 @@ LayergroupController.prototype.register = function(app) {
userMiddleware,
allowQueryParams(allowedDataviewQueryParams),
this.prepareContext,
this.dataviewSearch.bind(this)
this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
this.dataviewSearch(this.dataviewBackend)
);
app.get(
@ -153,7 +154,8 @@ LayergroupController.prototype.register = function(app) {
userMiddleware,
allowQueryParams(allowedDataviewQueryParams),
this.prepareContext,
this.dataviewSearch.bind(this)
this.getMapStoreMapConfigProvider(this.mapStore, this.userLimitsApi),
this.dataviewSearch(this.dataviewBackend)
);
app.get(
@ -215,28 +217,21 @@ LayergroupController.prototype.getDataview = function (dataviewBackend) {
}.bind(this);
};
LayergroupController.prototype.dataviewSearch = function(req, res, next) {
var self = this;
LayergroupController.prototype.dataviewSearch = function (dataviewBackend) {
return function dataviewSearchMiddlewarify (req, res, next) {
const { user, dataviewName, mapConfigProvider } = res.locals;
step(
function searchDataview() {
var mapConfigProvider = new MapStoreMapConfigProvider(
self.mapStore, res.locals.user, self.userLimitsApi, res.locals
);
self.dataviewBackend.search(mapConfigProvider, res.locals.user, req.params.dataviewName, res.locals, this);
},
function finish(err, searchResult, stats) {
dataviewBackend.search(mapConfigProvider, user, dataviewName, res.locals, (err, searchResult, stats) => {
req.profiler.add(stats || {});
if (err) {
err.label = 'GET DATAVIEW SEARCH';
next(err);
} else {
self.sendResponse(req, res, searchResult, 200);
return next(err);
}
}
);
this.sendResponse(req, res, searchResult, 200);
});
}.bind(this);
};
LayergroupController.prototype.attributes = function(req, res, next) {