From 0de272b195efcae8a45dcd784b6e04ce211aa5a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Tue, 13 Mar 2018 13:12:18 +0100 Subject: [PATCH 1/7] Extract middlewares form controller's context --- lib/cartodb/controllers/named_maps_admin.js | 93 +++++++++++---------- 1 file changed, 47 insertions(+), 46 deletions(-) diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index 0728b38c..ef1a0bcc 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -26,9 +26,9 @@ NamedMapsAdminController.prototype.register = function (app) { userMiddleware(), localsMiddleware(), credentialsMiddleware(), - this.checkContentType('POST', 'POST TEMPLATE'), - this.authorizedByAPIKey('create', 'POST TEMPLATE'), - this.create() + checkContentType('POST', 'POST TEMPLATE'), + authorizedByAPIKey(this.authApi, 'create', 'POST TEMPLATE'), + create(this.templateMaps) ); app.put( @@ -37,9 +37,9 @@ NamedMapsAdminController.prototype.register = function (app) { userMiddleware(), localsMiddleware(), credentialsMiddleware(), - this.checkContentType('PUT', 'PUT TEMPLATE'), - this.authorizedByAPIKey('update', 'PUT TEMPLATE'), - this.update() + checkContentType('PUT', 'PUT TEMPLATE'), + authorizedByAPIKey(this.authApi, 'update', 'PUT TEMPLATE'), + update(this.templateMaps) ); app.get( @@ -48,8 +48,8 @@ NamedMapsAdminController.prototype.register = function (app) { userMiddleware(), localsMiddleware(), credentialsMiddleware(), - this.authorizedByAPIKey('get', 'GET TEMPLATE'), - this.retrieve() + authorizedByAPIKey(this.authApi, 'get', 'GET TEMPLATE'), + retrieve(this.templateMaps) ); app.delete( @@ -58,8 +58,8 @@ NamedMapsAdminController.prototype.register = function (app) { userMiddleware(), localsMiddleware(), credentialsMiddleware(), - this.authorizedByAPIKey('delete', 'DELETE TEMPLATE'), - this.destroy() + authorizedByAPIKey(this.authApi, 'delete', 'DELETE TEMPLATE'), + destroy(this.templateMaps) ); app.get( @@ -68,8 +68,8 @@ NamedMapsAdminController.prototype.register = function (app) { userMiddleware(), localsMiddleware(), credentialsMiddleware(), - this.authorizedByAPIKey('list', 'GET TEMPLATE LIST'), - this.list() + authorizedByAPIKey(this.authApi, 'list', 'GET TEMPLATE LIST'), + list(this.templateMaps) ); app.options( @@ -78,10 +78,22 @@ NamedMapsAdminController.prototype.register = function (app) { ); }; -NamedMapsAdminController.prototype.authorizedByAPIKey = function (action, label) { +function checkContentType (action, label) { + return function checkContentTypeMiddleware (req, res, next) { + if (!req.is('application/json')) { + const error = new Error(`template ${action} data must be of type application/json`); + error.label = label; + return next(error); + } + next(); + }; +} + +function authorizedByAPIKey (authApi, action, label) { return function authorizedByAPIKeyMiddleware (req, res, next) { const { user } = res.locals; - this.authApi.authorizedByAPIKey(user, res, (err, authenticated) => { + + authApi.authorizedByAPIKey(user, res, (err, authenticated) => { if (err) { return next(err); } @@ -95,26 +107,15 @@ NamedMapsAdminController.prototype.authorizedByAPIKey = function (action, label) next(); }); - }.bind(this); -}; - -NamedMapsAdminController.prototype.checkContentType = function (action, label) { - return function checkContentTypeMiddleware (req, res, next) { - if (!req.is('application/json')) { - const error = new Error(`template ${action} data must be of type application/json`); - error.label = label; - return next(error); - } - next(); }; -}; +} -NamedMapsAdminController.prototype.create = function () { +function create (templateMaps) { return function createTemplateMiddleware (req, res, next) { const { user } = res.locals; const template = req.body; - this.templateMaps.addTemplate(user, template, (err, templateId) => { + templateMaps.addTemplate(user, template, (err, templateId) => { if (err) { return next(err); } @@ -124,16 +125,16 @@ NamedMapsAdminController.prototype.create = function () { const method = req.query.callback ? 'jsonp' : 'json'; res[method]({ template_id: templateId }); }); - }.bind(this); -}; + }; +} -NamedMapsAdminController.prototype.update = function () { +function update (templateMaps) { return function updateTemplateMiddleware (req, res, next) { const { user } = res.locals; const template = req.body; const templateId = templateName(req.params.template_id); - this.templateMaps.updTemplate(user, templateId, template, (err) => { + templateMaps.updTemplate(user, templateId, template, (err) => { if (err) { return next(err); } @@ -143,17 +144,17 @@ NamedMapsAdminController.prototype.update = function () { const method = req.query.callback ? 'jsonp' : 'json'; res[method]({ template_id: templateId }); }); - }.bind(this); -}; + }; +} -NamedMapsAdminController.prototype.retrieve = function () { +function retrieve (templateMaps) { return function retrieveTemplateMiddleware (req, res, next) { req.profiler.start('windshaft-cartodb.get_template'); const { user } = res.locals; const templateId = templateName(req.params.template_id); - this.templateMaps.getTemplate(user, templateId, (err, template) => { + templateMaps.getTemplate(user, templateId, (err, template) => { if (err) { return next(err); } @@ -172,17 +173,17 @@ NamedMapsAdminController.prototype.retrieve = function () { const method = req.query.callback ? 'jsonp' : 'json'; res[method]({ template }); }); - }.bind(this); -}; + }; +} -NamedMapsAdminController.prototype.destroy = function () { +function destroy (templateMaps) { return function destroyTemplateMiddleware (req, res, next) { req.profiler.start('windshaft-cartodb.delete_template'); const { user } = res.locals; const templateId = templateName(req.params.template_id); - this.templateMaps.delTemplate(user, templateId, (err/* , tpl_val */) => { + templateMaps.delTemplate(user, templateId, (err/* , tpl_val */) => { if (err) { return next(err); } @@ -192,16 +193,16 @@ NamedMapsAdminController.prototype.destroy = function () { const method = req.query.callback ? 'jsonp' : 'json'; res[method](''); }); - }.bind(this); -}; + }; +} -NamedMapsAdminController.prototype.list = function () { +function list (templateMaps) { return function listTemplatesMiddleware (req, res, next) { req.profiler.start('windshaft-cartodb.get_template_list'); const { user } = res.locals; - this.templateMaps.listTemplates(user, (err, templateIds) => { + templateMaps.listTemplates(user, (err, templateIds) => { if (err) { return next(err); } @@ -211,5 +212,5 @@ NamedMapsAdminController.prototype.list = function () { const method = req.query.callback ? 'jsonp' : 'json'; res[method]({ template_ids: templateIds }); }); - }.bind(this); -}; + }; +} From 24b76208ac484ab63cce369445ca7771d0ca34fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Tue, 13 Mar 2018 13:21:40 +0100 Subject: [PATCH 2/7] Improve naming --- lib/cartodb/controllers/named_maps_admin.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index ef1a0bcc..17e61f9a 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -28,7 +28,7 @@ NamedMapsAdminController.prototype.register = function (app) { credentialsMiddleware(), checkContentType('POST', 'POST TEMPLATE'), authorizedByAPIKey(this.authApi, 'create', 'POST TEMPLATE'), - create(this.templateMaps) + createTemplate(this.templateMaps) ); app.put( @@ -39,7 +39,7 @@ NamedMapsAdminController.prototype.register = function (app) { credentialsMiddleware(), checkContentType('PUT', 'PUT TEMPLATE'), authorizedByAPIKey(this.authApi, 'update', 'PUT TEMPLATE'), - update(this.templateMaps) + updateTemplate(this.templateMaps) ); app.get( @@ -49,7 +49,7 @@ NamedMapsAdminController.prototype.register = function (app) { localsMiddleware(), credentialsMiddleware(), authorizedByAPIKey(this.authApi, 'get', 'GET TEMPLATE'), - retrieve(this.templateMaps) + retrieveTemplate(this.templateMaps) ); app.delete( @@ -59,7 +59,7 @@ NamedMapsAdminController.prototype.register = function (app) { localsMiddleware(), credentialsMiddleware(), authorizedByAPIKey(this.authApi, 'delete', 'DELETE TEMPLATE'), - destroy(this.templateMaps) + destroyTemplate(this.templateMaps) ); app.get( @@ -69,7 +69,7 @@ NamedMapsAdminController.prototype.register = function (app) { localsMiddleware(), credentialsMiddleware(), authorizedByAPIKey(this.authApi, 'list', 'GET TEMPLATE LIST'), - list(this.templateMaps) + listTemplates(this.templateMaps) ); app.options( @@ -110,7 +110,7 @@ function authorizedByAPIKey (authApi, action, label) { }; } -function create (templateMaps) { +function createTemplate (templateMaps) { return function createTemplateMiddleware (req, res, next) { const { user } = res.locals; const template = req.body; @@ -128,7 +128,7 @@ function create (templateMaps) { }; } -function update (templateMaps) { +function updateTemplate (templateMaps) { return function updateTemplateMiddleware (req, res, next) { const { user } = res.locals; const template = req.body; @@ -147,7 +147,7 @@ function update (templateMaps) { }; } -function retrieve (templateMaps) { +function retrieveTemplate (templateMaps) { return function retrieveTemplateMiddleware (req, res, next) { req.profiler.start('windshaft-cartodb.get_template'); @@ -176,7 +176,7 @@ function retrieve (templateMaps) { }; } -function destroy (templateMaps) { +function destroyTemplate (templateMaps) { return function destroyTemplateMiddleware (req, res, next) { req.profiler.start('windshaft-cartodb.delete_template'); @@ -196,7 +196,7 @@ function destroy (templateMaps) { }; } -function list (templateMaps) { +function listTemplates (templateMaps) { return function listTemplatesMiddleware (req, res, next) { req.profiler.start('windshaft-cartodb.get_template_list'); From fc8f3fdf27775597e453ae3fcda0875f317e1beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Tue, 13 Mar 2018 13:31:49 +0100 Subject: [PATCH 3/7] Create send response middleware --- lib/cartodb/controllers/named_maps_admin.js | 51 +++++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index 17e61f9a..ec9d97c7 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -28,7 +28,8 @@ NamedMapsAdminController.prototype.register = function (app) { credentialsMiddleware(), checkContentType('POST', 'POST TEMPLATE'), authorizedByAPIKey(this.authApi, 'create', 'POST TEMPLATE'), - createTemplate(this.templateMaps) + createTemplate(this.templateMaps), + sendResponse() ); app.put( @@ -39,7 +40,8 @@ NamedMapsAdminController.prototype.register = function (app) { credentialsMiddleware(), checkContentType('PUT', 'PUT TEMPLATE'), authorizedByAPIKey(this.authApi, 'update', 'PUT TEMPLATE'), - updateTemplate(this.templateMaps) + updateTemplate(this.templateMaps), + sendResponse() ); app.get( @@ -49,7 +51,8 @@ NamedMapsAdminController.prototype.register = function (app) { localsMiddleware(), credentialsMiddleware(), authorizedByAPIKey(this.authApi, 'get', 'GET TEMPLATE'), - retrieveTemplate(this.templateMaps) + retrieveTemplate(this.templateMaps), + sendResponse() ); app.delete( @@ -59,7 +62,8 @@ NamedMapsAdminController.prototype.register = function (app) { localsMiddleware(), credentialsMiddleware(), authorizedByAPIKey(this.authApi, 'delete', 'DELETE TEMPLATE'), - destroyTemplate(this.templateMaps) + destroyTemplate(this.templateMaps), + sendResponse() ); app.get( @@ -69,7 +73,8 @@ NamedMapsAdminController.prototype.register = function (app) { localsMiddleware(), credentialsMiddleware(), authorizedByAPIKey(this.authApi, 'list', 'GET TEMPLATE LIST'), - listTemplates(this.templateMaps) + listTemplates(this.templateMaps), + sendResponse() ); app.options( @@ -85,6 +90,7 @@ function checkContentType (action, label) { error.label = label; return next(error); } + next(); }; } @@ -120,10 +126,9 @@ function createTemplate (templateMaps) { return next(err); } - res.status(200); + res.body = { template_id: templateId }; - const method = req.query.callback ? 'jsonp' : 'json'; - res[method]({ template_id: templateId }); + next(); }); }; } @@ -139,10 +144,9 @@ function updateTemplate (templateMaps) { return next(err); } - res.status(200); + res.body = { template_id: templateId }; - const method = req.query.callback ? 'jsonp' : 'json'; - res[method]({ template_id: templateId }); + next(); }); }; } @@ -168,10 +172,9 @@ function retrieveTemplate (templateMaps) { // so we remove it before returning to the user delete template.auth_id; - res.status(200); + res.body = { template }; - const method = req.query.callback ? 'jsonp' : 'json'; - res[method]({ template }); + next(); }); }; } @@ -188,10 +191,10 @@ function destroyTemplate (templateMaps) { return next(err); } - res.status(204); + res.statusCode = 204; + res.body = ''; - const method = req.query.callback ? 'jsonp' : 'json'; - res[method](''); + next(); }); }; } @@ -207,10 +210,18 @@ function listTemplates (templateMaps) { return next(err); } - res.status(200); + res.body = { template_ids: templateIds }; - const method = req.query.callback ? 'jsonp' : 'json'; - res[method]({ template_ids: templateIds }); + next(); }); }; } + +function sendResponse () { + return function sendResponseMiddleware (req, res) { + res.status(res.statusCode || 200); + + const method = req.query.callback ? 'jsonp' : 'json'; + res[method](res.body); + } +} From 2cc41612398d11f391d10f035e30b4b39909b5bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Tue, 13 Mar 2018 15:02:44 +0100 Subject: [PATCH 4/7] Missing semicolon --- lib/cartodb/controllers/named_maps_admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index ec9d97c7..79ab4451 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -223,5 +223,5 @@ function sendResponse () { const method = req.query.callback ? 'jsonp' : 'json'; res[method](res.body); - } + }; } From 421e611356dd3abd8ea16bac128e602b892af73c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 14 Mar 2018 17:22:47 +0100 Subject: [PATCH 5/7] Use objects instead of a list of parameters --- lib/cartodb/controllers/named_maps_admin.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index 79ab4451..ef49e652 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -26,7 +26,7 @@ NamedMapsAdminController.prototype.register = function (app) { userMiddleware(), localsMiddleware(), credentialsMiddleware(), - checkContentType('POST', 'POST TEMPLATE'), + checkContentType({ action: 'POST', label: 'POST TEMPLATE' }), authorizedByAPIKey(this.authApi, 'create', 'POST TEMPLATE'), createTemplate(this.templateMaps), sendResponse() @@ -38,7 +38,7 @@ NamedMapsAdminController.prototype.register = function (app) { userMiddleware(), localsMiddleware(), credentialsMiddleware(), - checkContentType('PUT', 'PUT TEMPLATE'), + checkContentType({ action: 'PUT', label: 'PUT TEMPLATE' }), authorizedByAPIKey(this.authApi, 'update', 'PUT TEMPLATE'), updateTemplate(this.templateMaps), sendResponse() @@ -83,7 +83,7 @@ NamedMapsAdminController.prototype.register = function (app) { ); }; -function checkContentType (action, label) { +function checkContentType ({ action, label }) { return function checkContentTypeMiddleware (req, res, next) { if (!req.is('application/json')) { const error = new Error(`template ${action} data must be of type application/json`); From 8d37e00869a724a6476b69008d4a67818b60598d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 14 Mar 2018 17:25:58 +0100 Subject: [PATCH 6/7] Use objects instead of parameter list --- lib/cartodb/controllers/named_maps_admin.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index ef49e652..1555273b 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -27,7 +27,7 @@ NamedMapsAdminController.prototype.register = function (app) { localsMiddleware(), credentialsMiddleware(), checkContentType({ action: 'POST', label: 'POST TEMPLATE' }), - authorizedByAPIKey(this.authApi, 'create', 'POST TEMPLATE'), + authorizedByAPIKey({ authApi: this.authApi, action: 'create', label: 'POST TEMPLATE' }), createTemplate(this.templateMaps), sendResponse() ); @@ -39,7 +39,7 @@ NamedMapsAdminController.prototype.register = function (app) { localsMiddleware(), credentialsMiddleware(), checkContentType({ action: 'PUT', label: 'PUT TEMPLATE' }), - authorizedByAPIKey(this.authApi, 'update', 'PUT TEMPLATE'), + authorizedByAPIKey({ authApi: this.authApi, action: 'update', label: 'PUT TEMPLATE' }), updateTemplate(this.templateMaps), sendResponse() ); @@ -50,7 +50,7 @@ NamedMapsAdminController.prototype.register = function (app) { userMiddleware(), localsMiddleware(), credentialsMiddleware(), - authorizedByAPIKey(this.authApi, 'get', 'GET TEMPLATE'), + authorizedByAPIKey({ authApi: this.authApi, action: 'get', label: 'GET TEMPLATE' }), retrieveTemplate(this.templateMaps), sendResponse() ); @@ -61,7 +61,7 @@ NamedMapsAdminController.prototype.register = function (app) { userMiddleware(), localsMiddleware(), credentialsMiddleware(), - authorizedByAPIKey(this.authApi, 'delete', 'DELETE TEMPLATE'), + authorizedByAPIKey({ authApi: this.authApi, action: 'delete', label: 'DELETE TEMPLATE' }), destroyTemplate(this.templateMaps), sendResponse() ); @@ -72,7 +72,7 @@ NamedMapsAdminController.prototype.register = function (app) { userMiddleware(), localsMiddleware(), credentialsMiddleware(), - authorizedByAPIKey(this.authApi, 'list', 'GET TEMPLATE LIST'), + authorizedByAPIKey({ authApi: this.authApi, action: 'list', label: 'GET TEMPLATE LIST' }), listTemplates(this.templateMaps), sendResponse() ); @@ -95,7 +95,7 @@ function checkContentType ({ action, label }) { }; } -function authorizedByAPIKey (authApi, action, label) { +function authorizedByAPIKey ({ authApi, action, label }) { return function authorizedByAPIKeyMiddleware (req, res, next) { const { user } = res.locals; From a34658c97f8377c5431693a5c44a4a0f6fbd4783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 14 Mar 2018 17:31:37 +0100 Subject: [PATCH 7/7] Use objects instead of param list --- lib/cartodb/controllers/named_maps_admin.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index 1555273b..986fef5c 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -28,7 +28,7 @@ NamedMapsAdminController.prototype.register = function (app) { credentialsMiddleware(), checkContentType({ action: 'POST', label: 'POST TEMPLATE' }), authorizedByAPIKey({ authApi: this.authApi, action: 'create', label: 'POST TEMPLATE' }), - createTemplate(this.templateMaps), + createTemplate({ templateMaps: this.templateMaps }), sendResponse() ); @@ -40,7 +40,7 @@ NamedMapsAdminController.prototype.register = function (app) { credentialsMiddleware(), checkContentType({ action: 'PUT', label: 'PUT TEMPLATE' }), authorizedByAPIKey({ authApi: this.authApi, action: 'update', label: 'PUT TEMPLATE' }), - updateTemplate(this.templateMaps), + updateTemplate({ templateMaps: this.templateMaps }), sendResponse() ); @@ -51,7 +51,7 @@ NamedMapsAdminController.prototype.register = function (app) { localsMiddleware(), credentialsMiddleware(), authorizedByAPIKey({ authApi: this.authApi, action: 'get', label: 'GET TEMPLATE' }), - retrieveTemplate(this.templateMaps), + retrieveTemplate({ templateMaps: this.templateMaps }), sendResponse() ); @@ -62,7 +62,7 @@ NamedMapsAdminController.prototype.register = function (app) { localsMiddleware(), credentialsMiddleware(), authorizedByAPIKey({ authApi: this.authApi, action: 'delete', label: 'DELETE TEMPLATE' }), - destroyTemplate(this.templateMaps), + destroyTemplate({ templateMaps: this.templateMaps }), sendResponse() ); @@ -73,7 +73,7 @@ NamedMapsAdminController.prototype.register = function (app) { localsMiddleware(), credentialsMiddleware(), authorizedByAPIKey({ authApi: this.authApi, action: 'list', label: 'GET TEMPLATE LIST' }), - listTemplates(this.templateMaps), + listTemplates({ templateMaps: this.templateMaps }), sendResponse() ); @@ -116,7 +116,7 @@ function authorizedByAPIKey ({ authApi, action, label }) { }; } -function createTemplate (templateMaps) { +function createTemplate ({ templateMaps }) { return function createTemplateMiddleware (req, res, next) { const { user } = res.locals; const template = req.body; @@ -133,7 +133,7 @@ function createTemplate (templateMaps) { }; } -function updateTemplate (templateMaps) { +function updateTemplate ({ templateMaps }) { return function updateTemplateMiddleware (req, res, next) { const { user } = res.locals; const template = req.body; @@ -151,7 +151,7 @@ function updateTemplate (templateMaps) { }; } -function retrieveTemplate (templateMaps) { +function retrieveTemplate ({ templateMaps }) { return function retrieveTemplateMiddleware (req, res, next) { req.profiler.start('windshaft-cartodb.get_template'); @@ -179,7 +179,7 @@ function retrieveTemplate (templateMaps) { }; } -function destroyTemplate (templateMaps) { +function destroyTemplate ({ templateMaps }) { return function destroyTemplateMiddleware (req, res, next) { req.profiler.start('windshaft-cartodb.delete_template'); @@ -199,7 +199,7 @@ function destroyTemplate (templateMaps) { }; } -function listTemplates (templateMaps) { +function listTemplates ({ templateMaps }) { return function listTemplatesMiddleware (req, res, next) { req.profiler.start('windshaft-cartodb.get_template_list');