Fix jshint max-complexity issue by using extract method

This commit is contained in:
Daniel García Aubert 2017-10-30 19:29:19 +01:00
parent b6c405bf68
commit fb3afaa6ab

View File

@ -184,7 +184,31 @@ MapController.prototype.create = function(req, res, prepareConfigFn, next) {
},
function finish(err, layergroup) {
if (err) {
if (Number.isFinite(err.layerIndex)) {
err = Number.isFinite(err.layerIndex) ? populateError(err, mapConfig) : err;
err.label = 'ANONYMOUS LAYERGROUP';
return next(err);
}
var analysesResults = context.analysesResults || [];
self.addDataviewsAndWidgetsUrls(res.locals.user, layergroup, mapConfig.obj());
self.addAnalysesMetadata(res.locals.user, layergroup, analysesResults, true);
addContextMetadata(layergroup, mapConfig.obj(), context);
res.set('X-Layergroup-Id', layergroup.layergroupid);
res.status(200);
if (req.query && req.query.callback) {
res.jsonp(layergroup);
} else {
res.json(layergroup);
}
}
);
};
function populateError(err, mapConfig) {
var error = new Error(err.message);
error.http_status = err.http_status;
@ -200,21 +224,8 @@ MapController.prototype.create = function(req, res, prepareConfigFn, next) {
type: mapConfig.layerType(err.layerIndex)
};
err = error;
return error;
}
err.label = 'ANONYMOUS LAYERGROUP';
next(err);
} else {
var analysesResults = context.analysesResults || [];
self.addDataviewsAndWidgetsUrls(res.locals.user, layergroup, mapConfig.obj());
self.addAnalysesMetadata(res.locals.user, layergroup, analysesResults, true);
addContextMetadata(layergroup, mapConfig.obj(), context);
res.set('X-Layergroup-Id', layergroup.layergroupid);
self.send(req, res, layergroup, 200);
}
}
);
};
function addContextMetadata(layergroup, mapConfig, context) {
if (layergroup.metadata && Array.isArray(layergroup.metadata.layers) && Array.isArray(mapConfig.layers)) {