Changeset View
Changeset View
Standalone View
Standalone View
lib/chip-types/aggregated-field.js
const Promise = require("bluebird"); | const Promise = require("bluebird"); | ||||
const AggregatedField = function(App, field_name, aggregations) { | const AggregatedField = function(App, field_name, aggregations) { | ||||
this.app = App; | this.app = App; | ||||
this.name = field_name; | this.name = field_name; | ||||
this.aggregations = aggregations; | this.aggregations = aggregations; | ||||
}; | }; | ||||
AggregatedField.prototype.get_aggregation_stages = function(context, item) { | AggregatedField.prototype.get_aggregation_stages = function(context, item) { | ||||
const self = this; | const self = this; | ||||
return Promise.all( | return Promise.all( | ||||
self.aggregations.map(function(e) { | self.aggregations.map(e => { | ||||
if (e instanceof Function) { | if (e instanceof Function) { | ||||
return e(context, item); | return e(context, item); | ||||
} else { | |||||
return e; | |||||
} | } | ||||
return e; | |||||
}) | }) | ||||
); | ); | ||||
}; | }; | ||||
module.exports = AggregatedField; | module.exports = AggregatedField; |