diff --git a/lib/cartodb/models/dataview/factory.js b/lib/cartodb/models/dataview/factory.js index 50814f23..fa55641c 100644 --- a/lib/cartodb/models/dataview/factory.js +++ b/lib/cartodb/models/dataview/factory.js @@ -1,18 +1,20 @@ -var dataviews = require('./'); +const dataviews = require('./'); -var DataviewFactory = { - dataviews: Object.keys(dataviews).reduce(function(allDataviews, dataviewClassName) { - allDataviews[dataviewClassName.toLowerCase()] = dataviews[dataviewClassName]; - return allDataviews; - }, {}), +module.exports = class DataviewFactory { + static get dataviews() { + return Object.keys(dataviews).reduce((allDataviews, dataviewClassName) => { + allDataviews[dataviewClassName.toLowerCase()] = dataviews[dataviewClassName]; + return allDataviews; + }, {}); + } + + static getDataview (query, dataviewDefinition) { + const { type, options, sql } = dataviewDefinition; - getDataview: function(query, dataviewDefinition) { - var type = dataviewDefinition.type; if (!this.dataviews[type]) { throw new Error('Invalid dataview type: "' + type + '"'); } - return new this.dataviews[type](query, dataviewDefinition.options, dataviewDefinition.sql); + + return new this.dataviews[type](query, options, sql); } }; - -module.exports = DataviewFactory;