Use destruturing assignment to format the formula result

This commit is contained in:
Daniel García Aubert 2017-09-15 10:58:11 +02:00
parent ecbc7a28e7
commit c00a93f414

View File

@ -103,23 +103,20 @@ module.exports = class Formula extends BaseDataview {
} }
format (result) { format (result) {
var formattedResult = { const {
result = 0,
nulls_count = 0,
nans_count = 0,
infinities_count = 0
} = result.rows[0] || {};
return {
operation: this.operation, operation: this.operation,
result: 0, result,
nulls: 0, nulls: nulls_count,
nans: 0, nans: nans_count,
infinities: 0 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 () { getType () {