diff --git a/lib/cartodb/models/mapconfig/adapter/vector-mapconfig-adapter.js b/lib/cartodb/models/mapconfig/adapter/vector-mapconfig-adapter.js index e1e4cc4a..76fdd836 100644 --- a/lib/cartodb/models/mapconfig/adapter/vector-mapconfig-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/vector-mapconfig-adapter.js @@ -1,23 +1,20 @@ -const AggregationMapConfig = require('../../aggregation/aggregation-mapconfig'); -const dateWrapper = require('../../../utils/date-wrapper'); const queryUtils = require('../../../utils/query-utils'); +const dateWrapper = require('../../../utils/date-wrapper'); -// Generate query to detect time columns -// For every column cast to unix timestamp -module.exports = class VectorMapConfigAdapter { +/** + * This middleware wraps the layer query transforming the date fields into numbers because mvt tiles + * doesnt support dates as primitive type. + * + * - This middleware is ONLY activated when the `dates_as_numbers` option is enabled for some layer in the mapConfig. + * - TODO: We currently support one single layer and we should define what to do with multiple layers. + */ +class VectorMapConfigAdapter { constructor(pgConnection) { this.pgConnection = pgConnection; } getMapConfig(user, requestMapConfig, params, context, callback) { - let mapConfig; - try { - mapConfig = new AggregationMapConfig(user, requestMapConfig, this.pgConnection); - } catch (err) { - return callback(err); - } - - if (!mapConfig.isVectorOnlyMapConfig()) { + if (!this._isDatesAsNumbersFlagEnabled(requestMapConfig)) { return callback(null, requestMapConfig); } @@ -25,7 +22,6 @@ module.exports = class VectorMapConfigAdapter { return callback(new Error('Get column types for multiple vector layers is not implemented')); } - this._wrapDates(requestMapConfig, user) .then(updatedRequestMapConfig => callback(null, updatedRequestMapConfig)) .catch(callback); @@ -55,4 +51,11 @@ module.exports = class VectorMapConfigAdapter { }); }); } -}; \ No newline at end of file + + _isDatesAsNumbersFlagEnabled(requestMapConfig) { + return requestMapConfig.layers.some(layer => layer.options.dates_as_numbers); + } +} + + +module.exports = VectorMapConfigAdapter; \ No newline at end of file diff --git a/test/acceptance/date-wrapping.spec.js b/test/acceptance/date-wrapping.spec.js index 5b8953a0..5049fd51 100644 --- a/test/acceptance/date-wrapping.spec.js +++ b/test/acceptance/date-wrapping.spec.js @@ -3,7 +3,7 @@ const assert = require('assert'); const TestClient = require('../support/test-client'); const mapConfigFactory = require('../fixtures/test_mapconfigFactory'); -describe.only('date-wrapping', () => { +describe('date-wrapping', () => { let testClient; describe('when a map instantiation has the "dates_as_numbers" option enabled', () => {