Create middleware for layergroup creation (anonymous map)

This commit is contained in:
Daniel García Aubert
2017-11-01 19:57:20 +01:00
parent e6bec5ccb0
commit 46c76d6a4c
+24 -22
View File
@@ -58,6 +58,7 @@ MapController.prototype.register = function(app) {
this.prepareContext,
createGetPrepareConfig,
this.prepareAdapterMapConfig.bind(this),
this.createLayergroup.bind(this),
this.createGet.bind(this),
mapErrorMiddleware({
label: 'ANONYMOUS LAYERGROUP',
@@ -71,6 +72,7 @@ MapController.prototype.register = function(app) {
this.prepareContext,
createPostPrepareConfig,
this.prepareAdapterMapConfig.bind(this),
this.createLayergroup.bind(this),
this.createPost.bind(this),
mapErrorMiddleware({
label: 'ANONYMOUS LAYERGROUP',
@@ -212,32 +214,32 @@ MapController.prototype.prepareAdapterMapConfig = function (req, res, next) {
});
};
MapController.prototype.createLayergroup = function(req, res, next) {
const requestMapConfig = req.body;
const { context, user } = res.locals;
const datasource = context.datasource || Datasource.EmptyDatasource();
const mapconfig = new MapConfig(requestMapConfig, datasource);
const mapconfigProvider = new CreateLayergroupMapConfigProvider(mapconfig, user, this.userLimitsApi, res.locals);
res.locals.mapconfig = mapconfig;
res.locals.analysesResults = context.analysesResults;
this.mapBackend.createLayergroup(mapconfig, res.locals, mapconfigProvider, (err, layergroup) => {
if (err) {
return next(err);
}
res.locals.layergroup = layergroup;
next();
});
};
MapController.prototype.create = function(req, res, next) {
var self = this;
step(
function createLayergroup() {
const requestMapConfig = req.body;
const { context } = res.locals;
const datasource = context.datasource || Datasource.EmptyDatasource();
const mapconfig = res.locals.mapconfig = new MapConfig(requestMapConfig, datasource);
self.mapBackend.createLayergroup(
mapconfig,
res.locals,
new CreateLayergroupMapConfigProvider(mapconfig, res.locals.user, self.userLimitsApi, res.locals),
this
);
},
function afterLayergroupCreate(err, layergroup) {
assert.ifError(err);
const { context } = res.locals;
res.locals.analysesResults = context.analysesResults;
res.locals.layergroup = layergroup;
res.locals.context = context;
function afterLayergroupCreate() {
const afterLayergroupCreate = self.afterLayergroupCreateBuilder({
includeQuery: true
});