diff --git a/lib/cartodb/models/dataview/factory.js b/lib/cartodb/models/dataview/factory.js index 6ad65312..fa55641c 100644 --- a/lib/cartodb/models/dataview/factory.js +++ b/lib/cartodb/models/dataview/factory.js @@ -9,10 +9,12 @@ module.exports = class DataviewFactory { } static getDataview (query, dataviewDefinition) { - const type = dataviewDefinition.type; + const { type, options, sql } = dataviewDefinition; + 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); } };