From c8000e5cf8a2fa2bd6af71c0fc4a9ba67dc3bcb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 1 Nov 2017 20:06:32 +0100 Subject: [PATCH] Make a middleware to respond layergroup --- lib/cartodb/controllers/map.js | 38 ++++++++++++++++------------------ 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/cartodb/controllers/map.js b/lib/cartodb/controllers/map.js index 2d65b801..901cc886 100644 --- a/lib/cartodb/controllers/map.js +++ b/lib/cartodb/controllers/map.js @@ -60,6 +60,7 @@ MapController.prototype.register = function(app) { this.prepareAdapterMapConfig.bind(this), this.createLayergroup.bind(this), this.createGet.bind(this), + respond, mapErrorMiddleware({ label: 'ANONYMOUS LAYERGROUP', augmentError: true @@ -74,6 +75,7 @@ MapController.prototype.register = function(app) { this.prepareAdapterMapConfig.bind(this), this.createLayergroup.bind(this), this.createPost.bind(this), + respond, mapErrorMiddleware({ label: 'ANONYMOUS LAYERGROUP', augmentError: true @@ -88,6 +90,7 @@ MapController.prototype.register = function(app) { this.getTemplate.bind(this), this.createLayergroupFromTemplate.bind(this), this.jsonp.bind(this), + respond, mapErrorMiddleware({ label: 'NAMED MAP LAYERGROUP' }) @@ -101,6 +104,7 @@ MapController.prototype.register = function(app) { this.getTemplate.bind(this), this.createLayergroupFromTemplate.bind(this), this.instantiate.bind(this), + respond, mapErrorMiddleware({ label: 'NAMED MAP LAYERGROUP' }) @@ -250,16 +254,7 @@ MapController.prototype.create = function(req, res, next) { if (err) { return next(err); } - - const { layergroup } = res.locals; - - res.status(200); - - if (req.query && req.query.callback) { - res.jsonp(layergroup); - } else { - res.json(layergroup); - } + next(); } ); }; @@ -333,20 +328,23 @@ MapController.prototype.instantiateTemplate = function(req, res, next) { if (err) { return next(err); } - - const { layergroup } = res.locals; - - res.status(200); - - if (req.query && req.query.callback) { - res.jsonp(layergroup); - } else { - res.json(layergroup); - } + next(); } ); }; +function respond (req, res) { + const { layergroup } = res.locals; + + res.status(200); + + if (req.query && req.query.callback) { + res.jsonp(layergroup); + } else { + res.json(layergroup); + } +} + MapController.prototype.afterLayergroupCreateBuilder = function (options = {}) { const self = this; const {