diff --git a/.eslint-bin/js-list.json b/.eslint-bin/js-list.json index c91d8b70..02851b3b 100644 --- a/.eslint-bin/js-list.json +++ b/.eslint-bin/js-list.json @@ -7,10 +7,14 @@ "src/index.js", "src/services/apimap-field-builder.js", "src/services/apimap-field-type-detector.js", + "src/services/leaderboard-stat-getter.js", + "src/services/line-stat-getter.js", "src/services/operator-value-parser.js", + "src/services/pie-stat-getter.js", "src/services/resource-finder.js", "src/services/resources-getter.js", "src/services/search-builder.js", + "src/services/value-stat-getter.js", "src/utils/database.js", "src/utils/operators.js", "src/utils/orm.js", diff --git a/CHANGELOG.md b/CHANGELOG.md index 39b7eb74..507e5978 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # Change Log ## [Unreleased] +### Changed +- Technical - Apply ESLint rules to old files. ## RELEASE 3.2.3 - 2019-06-21 ### Fixed diff --git a/src/services/leaderboard-stat-getter.js b/src/services/leaderboard-stat-getter.js index a8e72cc9..7601c334 100644 --- a/src/services/leaderboard-stat-getter.js +++ b/src/services/leaderboard-stat-getter.js @@ -1,62 +1,59 @@ -'use strict'; -var _ = require('lodash'); -var Interface = require('forest-express'); -var BaseStatGetter = require('./base-stat-getter'); +import _ from 'lodash'; +import { Schemas } from 'forest-express'; +import BaseStatGetter from './base-stat-getter'; function LeaderboardStatGetter(model, modelRelationship, params, options) { BaseStatGetter.call(this, model, params, options); - var labelField = params.label_field; - var aggregate = params.aggregate.toUpperCase(); - var aggregateField = params.aggregate_field; - var limit = params.limit; - var schema = Interface.Schemas.schemas[model.name]; - var schemaRelationship = Interface.Schemas.schemas[modelRelationship.name]; - var associationAs = schema.name; + const labelField = params.label_field; + const aggregate = params.aggregate.toUpperCase(); + const aggregateField = params.aggregate_field; + const { limit } = params; + const schema = Schemas.schemas[model.name]; + const schemaRelationship = Schemas.schemas[modelRelationship.name]; + let associationAs = schema.name; - _.each(modelRelationship.associations, function (association) { + _.each(modelRelationship.associations, (association) => { if (association.target.name === model.name && association.as) { associationAs = association.as; } }); - var groupBy = associationAs + '.' + labelField; + const groupBy = `${associationAs}.${labelField}`; function getAggregateField() { // NOTICE: As MySQL cannot support COUNT(table_name.*) syntax, fieldName cannot be '*'. - var fieldName = aggregateField || schemaRelationship.primaryKeys[0] || + const fieldName = aggregateField || schemaRelationship.primaryKeys[0] || schemaRelationship.fields[0].field; - return schemaRelationship.name + '.' + fieldName; + return `${schemaRelationship.name}.${fieldName}`; } - this.perform = function () { - return modelRelationship - .unscoped() - .findAll({ - attributes: [ - [options.sequelize.fn(aggregate, options.sequelize.col(getAggregateField())), 'value'] - ], - include: [{ - model: model, - attributes: [labelField], - as: associationAs, - required: true, - }], - group: groupBy, - order: [[options.sequelize.literal('value'), 'DESC']], - limit: limit, - raw: true - }) - .then(function (records) { - records = records.map(function (data) { - data.key = data[groupBy]; - delete data[groupBy]; - return data; - }); - - return { value: records }; + this.perform = () => modelRelationship + .unscoped() + .findAll({ + attributes: [ + [options.sequelize.fn(aggregate, options.sequelize.col(getAggregateField())), 'value'], + ], + include: [{ + model, + attributes: [labelField], + as: associationAs, + required: true, + }], + group: groupBy, + order: [[options.sequelize.literal('value'), 'DESC']], + limit, + raw: true, + }) + .then((records) => { + records = records.map((data) => { + data.key = data[groupBy]; + delete data[groupBy]; + return data; }); - }; + + return { value: records }; + }); } module.exports = LeaderboardStatGetter; diff --git a/src/services/line-stat-getter.js b/src/services/line-stat-getter.js index 98607b14..64f21fa0 100644 --- a/src/services/line-stat-getter.js +++ b/src/services/line-stat-getter.js @@ -1,109 +1,147 @@ -'use strict'; -var _ = require('lodash'); -var P = require('bluebird'); -var moment = require('moment'); -var BaseStatGetter = require('./base-stat-getter'); -var Database = require('../utils/database'); -var Interface = require('forest-express'); +import _ from 'lodash'; +import P from 'bluebird'; +import moment from 'moment'; +import { Schemas } from 'forest-express'; +import BaseStatGetter from './base-stat-getter'; +import { isMySQL, isMSSQL, isSQLite } from '../utils/database'; // jshint sub: true function LineStatGetter(model, params, opts) { BaseStatGetter.call(this, model, params, opts); - var schema = Interface.Schemas.schemas[model.name]; - var timeRange = params['time_range'].toLowerCase(); + const schema = Schemas.schemas[model.name]; + const timeRange = params.time_range.toLowerCase(); function getAggregateField() { // NOTICE: As MySQL cannot support COUNT(table_name.*) syntax, fieldName // cannot be '*'. - var fieldName = params['aggregate_field'] || schema.primaryKeys[0] || + const fieldName = params.aggregate_field || schema.primaryKeys[0] || schema.fields[0].field; - return schema.name + '.' + fieldName; + return `${schema.name}.${fieldName}`; } function getGroupByDateField() { - var fieldName = params['group_by_date_field']; - return schema.name + '.' + fieldName; + const fieldName = params.group_by_date_field; + return `${schema.name}.${fieldName}`; } - var groupByDateField = getGroupByDateField(); + const groupByDateField = getGroupByDateField(); - function getGroupByDateFieldFormatedForMySQL(timeRange) { - switch (timeRange) { + function getGroupByDateFieldFormatedForMySQL(currentTimeRange) { + const groupByDateFieldFormated = `\`${groupByDateField.replace('.', '`.`')}\``; + switch (currentTimeRange) { case 'day': - return opts.sequelize.fn('DATE_FORMAT', opts.sequelize.col(groupByDateField), - '%Y-%m-%d 00:00:00'); + return opts.sequelize.fn( + 'DATE_FORMAT', + opts.sequelize.col(groupByDateField), + '%Y-%m-%d 00:00:00', + ); case 'week': - var groupByDateFieldFormated = '`' + groupByDateField.replace('.', '`.`') + '`'; - return opts.sequelize.literal('DATE_FORMAT(DATE_SUB(' + groupByDateFieldFormated + - ', INTERVAL ((7 + WEEKDAY(' + groupByDateFieldFormated + ')) % 7) DAY), ' + - '\'%Y-%m-%d 00:00:00\')'); + return opts.sequelize + .literal(`DATE_FORMAT(DATE_SUB(${groupByDateFieldFormated}, \ +INTERVAL ((7 + WEEKDAY(${groupByDateFieldFormated})) % 7) DAY), '%Y-%m-%d 00:00:00')`); case 'month': - return opts.sequelize.fn('DATE_FORMAT', opts.sequelize.col(groupByDateField), - '%Y-%m-01 00:00:00'); + return opts.sequelize.fn( + 'DATE_FORMAT', + opts.sequelize.col(groupByDateField), + '%Y-%m-01 00:00:00', + ); case 'year': - return opts.sequelize.fn('DATE_FORMAT', opts.sequelize.col(groupByDateField), - '%Y-01-01 00:00:00'); + return opts.sequelize.fn( + 'DATE_FORMAT', + opts.sequelize.col(groupByDateField), + '%Y-01-01 00:00:00', + ); + default: + return null; } } - function getGroupByDateFieldFormatedForMSSQL(timeRange) { - switch (timeRange) { + function getGroupByDateFieldFormatedForMSSQL(currentTimeRange) { + const groupByDateFieldFormated = `[${groupByDateField.replace('.', '].[')}]`; + switch (currentTimeRange) { case 'day': - return opts.sequelize.fn('FORMAT', opts.sequelize.col(groupByDateField), - 'yyyy-MM-dd 00:00:00'); + return opts.sequelize.fn( + 'FORMAT', + opts.sequelize.col(groupByDateField), + 'yyyy-MM-dd 00:00:00', + ); case 'week': - var groupByDateFieldFormated = '[' + groupByDateField.replace('.', '].[') + ']'; - return opts.sequelize.literal('FORMAT(DATEADD(DAY, -DATEPART(dw,' + - groupByDateFieldFormated + '),' + groupByDateFieldFormated + '), \'yyyy-MM-dd 00:00:00\')'); + return opts.sequelize + .literal(`FORMAT(DATEADD(DAY, -DATEPART(dw,${groupByDateFieldFormated}),\ +${groupByDateFieldFormated}), 'yyyy-MM-dd 00:00:00')`); case 'month': - return opts.sequelize.fn('FORMAT', opts.sequelize.col(groupByDateField), - 'yyyy-MM-01 00:00:00'); + return opts.sequelize.fn( + 'FORMAT', + opts.sequelize.col(groupByDateField), + 'yyyy-MM-01 00:00:00', + ); case 'year': - return opts.sequelize.fn('FORMAT', opts.sequelize.col(groupByDateField), - 'yyyy-01-01 00:00:00'); + return opts.sequelize.fn( + 'FORMAT', + opts.sequelize.col(groupByDateField), + 'yyyy-01-01 00:00:00', + ); + default: + return null; } } - function getGroupByDateFieldFormatedForSQLite(timeRange) { - switch (timeRange) { + function getGroupByDateFieldFormatedForSQLite(currentTimeRange) { + switch (currentTimeRange) { case 'day': { - return opts.sequelize.fn('STRFTIME', '%Y-%m-%d', - opts.sequelize.col(groupByDateField)); + return opts.sequelize.fn( + 'STRFTIME', + '%Y-%m-%d', + opts.sequelize.col(groupByDateField), + ); } case 'week': { - return opts.sequelize.fn('STRFTIME', '%Y-%W', - opts.sequelize.col(groupByDateField)); + return opts.sequelize.fn( + 'STRFTIME', + '%Y-%W', + opts.sequelize.col(groupByDateField), + ); } case 'month': { - return opts.sequelize.fn('STRFTIME', '%Y-%m-01', - opts.sequelize.col(groupByDateField)); + return opts.sequelize.fn( + 'STRFTIME', + '%Y-%m-01', + opts.sequelize.col(groupByDateField), + ); } case 'year': { - return opts.sequelize.fn('STRFTIME', '%Y-01-01', - opts.sequelize.col(groupByDateField)); + return opts.sequelize.fn( + 'STRFTIME', + '%Y-01-01', + opts.sequelize.col(groupByDateField), + ); } + default: + return null; } } function getGroupByDateInterval() { - if (Database.isMySQL(opts)) { + if (isMySQL(opts)) { return [getGroupByDateFieldFormatedForMySQL(timeRange), 'date']; - } else if (Database.isMSSQL(opts)) { + } else if (isMSSQL(opts)) { return [getGroupByDateFieldFormatedForMSSQL(timeRange), 'date']; - } else if (Database.isSQLite(opts)) { + } else if (isSQLite(opts)) { return [getGroupByDateFieldFormatedForSQLite(timeRange), 'date']; - } else { - return [ - opts.sequelize.fn('to_char', - opts.sequelize.fn('date_trunc', params['time_range'], - opts.sequelize.literal('"' + getGroupByDateField() - .replace('.', '"."') + '" at time zone \'' + params.timezone + '\'')), - 'YYYY-MM-DD 00:00:00' - ), - 'date' - ]; } + return [ + opts.sequelize.fn( + 'to_char', + opts.sequelize.fn( + 'date_trunc', + params.time_range, + opts.sequelize.literal(`"${getGroupByDateField().replace('.', '"."')}" at time zone '${params.timezone}'`), + ), + 'YYYY-MM-DD 00:00:00', + ), + 'date', + ]; } function getFormat() { @@ -112,56 +150,51 @@ function LineStatGetter(model, params, opts) { case 'week': return '[W]w-YYYY'; case 'month': return 'MMM YY'; case 'year': return 'YYYY'; + default: return null; } } function fillEmptyDateInterval(records) { if (records.length) { - var sqlFormat = 'YYYY-MM-DD 00:00:00'; - if (Database.isSQLite(opts) && timeRange === 'week') { + let sqlFormat = 'YYYY-MM-DD 00:00:00'; + if (isSQLite(opts) && timeRange === 'week') { sqlFormat = 'YYYY-WW'; } - var firstDate = moment(records[0].label, sqlFormat); - var lastDate = moment(records[records.length - 1].label, sqlFormat); - - for (var i = firstDate ; i.toDate() <= lastDate.toDate() ; - i = i.add(1, timeRange)) { + const firstDate = moment(records[0].label, sqlFormat); + const lastDate = moment(records[records.length - 1].label, sqlFormat); - var label = i.format(sqlFormat); - if (!_.find(records, { label: label })) { - records.push({ label: label, values: { value: 0 }}); + for (let i = firstDate; i.toDate() <= lastDate.toDate(); i = i.add(1, timeRange)) { + const label = i.format(sqlFormat); + if (!_.find(records, { label })) { + records.push({ label, values: { value: 0 } }); } } records = _.sortBy(records, 'label'); - return _.map(records, function (record) { - return { - label: moment(record.label, sqlFormat).format(getFormat()), - values: record.values - }; - }); - } else { - return records; + return _.map(records, record => ({ + label: moment(record.label, sqlFormat).format(getFormat()), + values: record.values, + })); } + return records; } function getAggregate() { return [ - opts.sequelize.fn(params.aggregate.toLowerCase(), - opts.sequelize.col(getAggregateField())), - 'value' + opts.sequelize.fn(params.aggregate.toLowerCase(), opts.sequelize.col(getAggregateField())), + 'value', ]; } function getIncludes() { - var includes = []; - _.values(model.associations).forEach(function (association) { + const includes = []; + _.values(model.associations).forEach((association) => { if (['HasOne', 'BelongsTo'].indexOf(association.associationType) > -1) { includes.push({ model: association.target.unscoped(), as: association.associationAccessor, - attributes: [] + attributes: [], }); } }); @@ -170,34 +203,28 @@ function LineStatGetter(model, params, opts) { } function getGroupBy() { - return Database.isMSSQL(opts) ? [getGroupByDateFieldFormatedForMSSQL(timeRange)] : [opts.sequelize.literal('1')]; + return isMSSQL(opts) ? [getGroupByDateFieldFormatedForMSSQL(timeRange)] : [opts.sequelize.literal('1')]; } function getOrder() { - return Database.isMSSQL(opts) ? [getGroupByDateFieldFormatedForMSSQL(timeRange)] : [opts.sequelize.literal('1')]; + return isMSSQL(opts) ? [getGroupByDateFieldFormatedForMSSQL(timeRange)] : [opts.sequelize.literal('1')]; } - this.perform = function () { - return model.unscoped().findAll({ + this.perform = () => model + .unscoped() + .findAll({ attributes: [getGroupByDateInterval(), getAggregate()], include: getIncludes(), where: this.getFilters(), group: getGroupBy(), order: getOrder(), - raw: true + raw: true, }) - .then(function (records) { - return P.map(records, function (record) { - return { - label: record.date, - values: { value: parseInt(record.value) } - }; - }); - }) - .then(function (records) { - return { value: fillEmptyDateInterval(records) }; - }); - }; + .then(records => P.map(records, record => ({ + label: record.date, + values: { value: parseInt(record.value, 10) }, + }))) + .then(records => ({ value: fillEmptyDateInterval(records) })); } module.exports = LineStatGetter; diff --git a/src/services/pie-stat-getter.js b/src/services/pie-stat-getter.js index d31781d0..ffb17155 100644 --- a/src/services/pie-stat-getter.js +++ b/src/services/pie-stat-getter.js @@ -1,49 +1,48 @@ -'use strict'; -/* jshint sub: true */ -var _ = require('lodash'); -var P = require('bluebird'); -var moment = require('moment'); -var orm = require('../utils/orm'); -var BaseStatGetter = require('./base-stat-getter'); -var Database = require('../utils/database'); -var Interface = require('forest-express'); +import _ from 'lodash'; +import P from 'bluebird'; +import moment from 'moment'; +import { Schemas } from 'forest-express'; +import { isVersionLessThan4 } from '../utils/orm'; +import BaseStatGetter from './base-stat-getter'; +import { isMSSQL } from '../utils/database'; // NOTICE: These aliases are not camelcased to prevent issues with Sequelize. -var ALIAS_GROUP_BY = 'forest_alias_groupby'; -var ALIAS_AGGREGATE = 'forest_alias_aggregate'; +const ALIAS_GROUP_BY = 'forest_alias_groupby'; +const ALIAS_AGGREGATE = 'forest_alias_aggregate'; function PieStatGetter(model, params, opts) { BaseStatGetter.call(this, model, params, opts); - var needsDateOnlyFormating = orm.isVersionLessThan4(opts.sequelize); + const needsDateOnlyFormating = isVersionLessThan4(opts.sequelize); - var schema = Interface.Schemas.schemas[model.name]; - var associationSplit,associationCollection, associationField, - associationSchema, field; + const schema = Schemas.schemas[model.name]; + let associationSplit; + let associationCollection; + let associationField; + let associationSchema; + let field; - if (params['group_by_field'].indexOf(':') === -1) { - field = _.find(schema.fields, function (field) { - return field.field === params['group_by_field']; - }); + if (params.group_by_field.indexOf(':') === -1) { + field = _.find(schema.fields, currentField => currentField.field === params.group_by_field); } else { - associationSplit = params['group_by_field'].split(':'); + associationSplit = params.group_by_field.split(':'); associationCollection = associationSplit[0]; associationField = associationSplit[1]; - associationSchema = Interface.Schemas.schemas[associationCollection]; - field = _.find(associationSchema.fields, function (field) { - return field.field === associationField; - }); + associationSchema = Schemas.schemas[associationCollection]; + field = _.find( + associationSchema.fields, + currentField => currentField.field === associationField, + ); } function getGroupByField() { - if (params['group_by_field'].indexOf(':') === -1) { - return schema.name + '.' + params['group_by_field']; - } else { - return params['group_by_field'].replace(':', '.'); + if (params.group_by_field.indexOf(':') === -1) { + return `${schema.name}.${params.group_by_field}`; } + return params.group_by_field.replace(':', '.'); } - var groupByField = getGroupByField(); + const groupByField = getGroupByField(); function getAggregate() { return params.aggregate.toLowerCase(); @@ -52,19 +51,19 @@ function PieStatGetter(model, params, opts) { function getAggregateField() { // NOTICE: As MySQL cannot support COUNT(table_name.*) syntax, fieldName // cannot be '*'. - var fieldName = params['aggregate_field'] || schema.primaryKeys[0] || + const fieldName = params.aggregate_field || schema.primaryKeys[0] || schema.fields[0].field; - return schema.name + '.' + fieldName; + return `${schema.name}.${fieldName}`; } function getIncludes() { - var includes = []; - _.values(model.associations).forEach(function (association) { + const includes = []; + _.values(model.associations).forEach((association) => { if (['HasOne', 'BelongsTo'].indexOf(association.associationType) > -1) { includes.push({ model: association.target.unscoped(), as: association.associationAccessor, - attributes: [] + attributes: [], }); } }); @@ -73,19 +72,18 @@ function PieStatGetter(model, params, opts) { } function getGroupBy() { - return Database.isMSSQL(opts) ? [opts.sequelize.col(groupByField)] : - [ALIAS_GROUP_BY]; + return isMSSQL(opts) ? [opts.sequelize.col(groupByField)] : [ALIAS_GROUP_BY]; } - function formatResults (records) { - return P.map(records, function (record) { - var key; + function formatResults(records) { + return P.map(records, (record) => { + let key; if (field.type === 'Date') { key = moment(record[ALIAS_GROUP_BY]).format('DD/MM/YYYY HH:mm:ss'); } else if (field.type === 'Dateonly' && needsDateOnlyFormating) { - var offsetServer = moment().utcOffset() / 60; - var dateonly = moment.utc(record[ALIAS_GROUP_BY]) + const offsetServer = moment().utcOffset() / 60; + const dateonly = moment.utc(record[ALIAS_GROUP_BY]) .add(offsetServer, 'h'); key = dateonly.format('DD/MM/YYYY'); } else { @@ -93,36 +91,36 @@ function PieStatGetter(model, params, opts) { } return { - key: key, - value: record[ALIAS_AGGREGATE] + key, + value: record[ALIAS_AGGREGATE], }; }); } - this.perform = function () { - return model.unscoped().findAll({ + this.perform = () => model + .unscoped() + .findAll({ attributes: [ [ opts.sequelize.col(groupByField), - ALIAS_GROUP_BY + ALIAS_GROUP_BY, ], [ - opts.sequelize.fn(getAggregate(), - opts.sequelize.col(getAggregateField())), - ALIAS_AGGREGATE - ] + opts.sequelize.fn( + getAggregate(), + opts.sequelize.col(getAggregateField()), + ), + ALIAS_AGGREGATE, + ], ], include: getIncludes(), where: this.getFilters(), group: getGroupBy(), order: [[opts.sequelize.literal(ALIAS_AGGREGATE), 'DESC']], - raw: true + raw: true, }) .then(formatResults) - .then(function (records) { - return { value: records }; - }); - }; + .then(records => ({ value: records })); } module.exports = PieStatGetter; diff --git a/src/services/value-stat-getter.js b/src/services/value-stat-getter.js index ad2fc38c..17892d7f 100644 --- a/src/services/value-stat-getter.js +++ b/src/services/value-stat-getter.js @@ -1,17 +1,16 @@ -'use strict'; -var _ = require('lodash'); -var Operators = require('../utils/operators'); -var BaseStatGetter = require('./base-stat-getter'); -var OperatorDateIntervalParser = require('./operator-date-interval-parser'); -var Interface = require('forest-express'); +import _ from 'lodash'; +import { Schemas } from 'forest-express'; +import Operators from '../utils/operators'; +import BaseStatGetter from './base-stat-getter'; +import OperatorDateIntervalParser from './operator-date-interval-parser'; // jshint sub: true function ValueStatGetter(model, params, options) { BaseStatGetter.call(this, model, params, options); - var OPERATORS = new Operators(options); + const OPERATORS = new Operators(options); - var schema = Interface.Schemas.schemas[model.name]; + const schema = Schemas.schemas[model.name]; function getAggregate() { return params.aggregate.toLowerCase(); } @@ -19,19 +18,18 @@ function ValueStatGetter(model, params, options) { function getAggregateField() { // NOTICE: As MySQL cannot support COUNT(table_name.*) syntax, fieldName // cannot be '*'. - var fieldName = params['aggregate_field'] || schema.primaryKeys[0]|| - schema.fields[0].field; - return schema.name + '.' + fieldName; + const fieldName = params.aggregate_field || schema.primaryKeys[0] || schema.fields[0].field; + return `${schema.name}.${fieldName}`; } function getIncludes() { - var includes = []; - _.values(model.associations).forEach(function (association) { + const includes = []; + _.values(model.associations).forEach((association) => { if (['HasOne', 'BelongsTo'].indexOf(association.associationType) > -1) { includes.push({ model: association.target.unscoped(), as: association.associationAccessor, - attributes: [] + attributes: [], }); } }); @@ -40,10 +38,10 @@ function ValueStatGetter(model, params, options) { } function getIntervalDateFilterForPrevious() { - var intervalDateFilter; + let intervalDateFilter; - params.filters.forEach(function (filter) { - var operatorValueParser = + params.filters.forEach((filter) => { + const operatorValueParser = new OperatorDateIntervalParser(filter.value, params.timezone, options); if (operatorValueParser.hasPreviousInterval()) { intervalDateFilter = filter; @@ -52,30 +50,32 @@ function ValueStatGetter(model, params, options) { return intervalDateFilter; } - this.perform = function () { - var countCurrent; - var aggregateField = getAggregateField(); - var aggregate = getAggregate(); - var filters = this.getFilters(); - var filterDateIntervalForPrevious = getIntervalDateFilterForPrevious(); + this.perform = () => { + let countCurrent; + const aggregateField = getAggregateField(); + const aggregate = getAggregate(); + const filters = this.getFilters(); + const filterDateIntervalForPrevious = getIntervalDateFilterForPrevious(); return model .unscoped() .aggregate(aggregateField, aggregate, { include: getIncludes(), - where: filters + where: filters, }) - .then(function (count) { + .then((count) => { countCurrent = count || 0; // NOTICE: Search for previous interval value only if the filterType is // 'AND', it would not be pertinent for a 'OR' filterType. if (filterDateIntervalForPrevious && params.filterType === 'and') { - var operatorValueParser = new OperatorDateIntervalParser( - filterDateIntervalForPrevious.value, params.timezone, options + const operatorValueParser = new OperatorDateIntervalParser( + filterDateIntervalForPrevious.value, + params.timezone, + options, ); - var conditions = filters[OPERATORS.AND]; - conditions.forEach(function (condition) { + const conditions = filters[OPERATORS.AND]; + conditions.forEach((condition) => { if (condition[filterDateIntervalForPrevious.field]) { condition[filterDateIntervalForPrevious.field] = operatorValueParser.getIntervalDateFilterForPreviousInterval(); @@ -85,20 +85,18 @@ function ValueStatGetter(model, params, options) { .unscoped() .aggregate(aggregateField, aggregate, { include: getIncludes(), - where: filters + where: filters, }) - .then(function (count) { return count || 0; }); + .then(currentCount => currentCount || 0); } return undefined; }) - .then(function (countPrevious) { - return { - value: { - countCurrent: countCurrent, - countPrevious: countPrevious - } - }; - }); + .then(countPrevious => ({ + value: { + countCurrent, + countPrevious, + }, + })); }; }