From 68f5ee7bde138a7589bb9fb8a59e5c67db6cf711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Fri, 11 May 2018 16:18:52 +0200 Subject: [PATCH] Use ES6 class syntax --- .../api/template/named-template-controller.js | 150 +++++++++--------- 1 file changed, 72 insertions(+), 78 deletions(-) diff --git a/lib/cartodb/api/template/named-template-controller.js b/lib/cartodb/api/template/named-template-controller.js index 86613c5e..f85892bd 100644 --- a/lib/cartodb/api/template/named-template-controller.js +++ b/lib/cartodb/api/template/named-template-controller.js @@ -33,88 +33,82 @@ const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit; * @param {StatsBackend} statsBackend * @constructor */ -function NamedMapController ( - pgConnection, - templateMaps, - mapBackend, - metadataBackend, - surrogateKeysCache, - userLimitsBackend, - layergroupAffectedTables, - mapConfigAdapter, - statsBackend, - authBackend, - layergroupMetadata -) { - this.pgConnection = pgConnection; - this.templateMaps = templateMaps; - this.mapBackend = mapBackend; - this.metadataBackend = metadataBackend; - this.surrogateKeysCache = surrogateKeysCache; - this.userLimitsBackend = userLimitsBackend; - this.layergroupAffectedTables = layergroupAffectedTables; - this.mapConfigAdapter = mapConfigAdapter; - this.statsBackend = statsBackend; - this.authBackend = authBackend; - this.layergroupMetadata = layergroupMetadata; -} +module.exports = class NamedMapController { + constructor ( + pgConnection, + templateMaps, + mapBackend, + metadataBackend, + surrogateKeysCache, + userLimitsBackend, + layergroupAffectedTables, + mapConfigAdapter, + statsBackend, + authBackend, + layergroupMetadata + ) { + this.pgConnection = pgConnection; + this.templateMaps = templateMaps; + this.mapBackend = mapBackend; + this.metadataBackend = metadataBackend; + this.surrogateKeysCache = surrogateKeysCache; + this.userLimitsBackend = userLimitsBackend; + this.layergroupAffectedTables = layergroupAffectedTables; + this.mapConfigAdapter = mapConfigAdapter; + this.statsBackend = statsBackend; + this.authBackend = authBackend; + this.layergroupMetadata = layergroupMetadata; + } -module.exports = NamedMapController; + register (templateRouter) { + templateRouter.get(`/:template_id/jsonp`, this.composeInstantiateTemplateMiddleware()); -NamedMapController.prototype.register = function (templateRouter) { - templateRouter.get( - `/:template_id/jsonp`, - this.composeInstantiateTemplateMiddleware() - ); + templateRouter.post(`/:template_id`, this.composeInstantiateTemplateMiddleware()); + } - templateRouter.post( - `/:template_id`, - this.composeInstantiateTemplateMiddleware() - ); -}; + composeInstantiateTemplateMiddleware () { + const isTemplateInstantiation = true; + const useTemplateHash = true; + const includeQuery = false; + const label = 'NAMED MAP LAYERGROUP'; + const addContext = false; -NamedMapController.prototype.composeInstantiateTemplateMiddleware = function () { - const isTemplateInstantiation = true; - const useTemplateHash = true; - const includeQuery = false; - const label = 'NAMED MAP LAYERGROUP'; - const addContext = false; - - return [ - credentials(), - authorize(this.authBackend), - dbConnSetup(this.pgConnection), - rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED), - cleanUpQueryParams(['aggregation']), - initProfiler(isTemplateInstantiation), - checkJsonContentType(), - checkInstantiteLayergroup(), - getTemplate( - this.templateMaps, - this.pgConnection, - this.metadataBackend, - this.userLimitsBackend, - this.mapConfigAdapter, - this.layergroupAffectedTables - ), - instantiateLayergroup( - this.mapBackend, - this.userLimitsBackend, - this.pgConnection, - this.layergroupAffectedTables - ), - incrementMapViewCount(this.metadataBackend), - augmentLayergroupData(), - cacheControlHeader({ ttl: global.environment.varnish.layergroupTtl || 86400, revalidate: true }), - cacheChannelHeader(), - surrogateKeyHeader({ surrogateKeysCache: this.surrogateKeysCache }), - lastModifiedHeader({ now: true }), - lastUpdatedTimeLayergroup(), - layerStats(this.pgConnection, this.statsBackend), - layergroupIdHeader(this.templateMaps ,useTemplateHash), - layergroupMetadata(this.layergroupMetadata, includeQuery), - mapError({ label, addContext }) - ]; + return [ + credentials(), + authorize(this.authBackend), + dbConnSetup(this.pgConnection), + rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED), + cleanUpQueryParams(['aggregation']), + initProfiler(isTemplateInstantiation), + checkJsonContentType(), + checkInstantiteLayergroup(), + getTemplate( + this.templateMaps, + this.pgConnection, + this.metadataBackend, + this.userLimitsBackend, + this.mapConfigAdapter, + this.layergroupAffectedTables + ), + instantiateLayergroup( + this.mapBackend, + this.userLimitsBackend, + this.pgConnection, + this.layergroupAffectedTables + ), + incrementMapViewCount(this.metadataBackend), + augmentLayergroupData(), + cacheControlHeader({ ttl: global.environment.varnish.layergroupTtl || 86400, revalidate: true }), + cacheChannelHeader(), + surrogateKeyHeader({ surrogateKeysCache: this.surrogateKeysCache }), + lastModifiedHeader({ now: true }), + lastUpdatedTimeLayergroup(), + layerStats(this.pgConnection, this.statsBackend), + layergroupIdHeader(this.templateMaps ,useTemplateHash), + layergroupMetadata(this.layergroupMetadata, includeQuery), + mapError({ label, addContext }) + ]; + } }; function checkInstantiteLayergroup () {