From c00a93f4144abf7eccaf9c7691c2138218866950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Fri, 15 Sep 2017 10:58:11 +0200 Subject: [PATCH] Use destruturing assignment to format the formula result --- lib/cartodb/models/dataview/formula.js | 27 ++++++++++++-------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/lib/cartodb/models/dataview/formula.js b/lib/cartodb/models/dataview/formula.js index efaeb0c6..2172beab 100644 --- a/lib/cartodb/models/dataview/formula.js +++ b/lib/cartodb/models/dataview/formula.js @@ -103,23 +103,20 @@ module.exports = class Formula extends BaseDataview { } format (result) { - var formattedResult = { + const { + result = 0, + nulls_count = 0, + nans_count = 0, + infinities_count = 0 + } = result.rows[0] || {}; + + return { operation: this.operation, - result: 0, - nulls: 0, - nans: 0, - infinities: 0 + result, + nulls: nulls_count, + nans: nans_count, + infinities: infinities_count }; - - if (result.rows.length) { - formattedResult.operation = this.operation; - formattedResult.result = result.rows[0].result; - formattedResult.nulls = result.rows[0].nulls_count; - formattedResult.nans = result.rows[0].nans_count; - formattedResult.infinities = result.rows[0].infinities_count; - } - - return formattedResult; } getType () {