Extract method to check valid aggregation

This commit is contained in:
Daniel García Aubert
2017-09-11 18:57:16 +02:00
parent fd9534797c
commit 09981c2560
@@ -187,7 +187,7 @@ module.exports = class DateHistogram extends BaseHistogram {
}
_buildQuery (psql, override, callback) {
if (!DATE_AGGREGATIONS.hasOwnProperty(this._getAggregation(override))) {
if (!this.isValidAggregation(override)) {
return callback(new Error('Invalid aggregation value. Valid ones: ' +
Object.keys(DATE_AGGREGATIONS).join(', ')
));
@@ -221,6 +221,10 @@ module.exports = class DateHistogram extends BaseHistogram {
return callback(null, histogramSql);
}
_isValidAggregation (override) {
return DATE_AGGREGATIONS.hasOwnProperty(this._getAggregation(override));
}
_getAutomaticAggregation (psql, callback) {
const dateIntervalQuery = dateIntervalQueryTpl({
query: this.query,