diff options
Diffstat (limited to 'src/web')
-rw-r--r-- | src/web/DillerWeb.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/web/DillerWeb.js b/src/web/DillerWeb.js index b42e47e..cf65f1b 100644 --- a/src/web/DillerWeb.js +++ b/src/web/DillerWeb.js @@ -111,21 +111,24 @@ function DillerWeb(config, mqttClient, tx) { var from = req.query.from && moment(req.query.from, isoFormat); var to = req.query.to && moment(req.query.to, isoFormat); var limit = req.query.limit || 10; + var aggregateLevel = req.query.aggregateLevel; tx(function (tx, dao) { var propertyId = Number(req.params.propertyId); + var validAggregateLevel = aggregateLevel == 'minute' || aggregateLevel == 'hour' || aggregateLevel == 'day'; + if (from || to) { from = (from || moment()).startOf('hour'); to = (to || moment()).startOf('hour'); - if (typeof propertyId !== 'number' || !from.isValid() || !to.isValid()) { - log.info('getValues: Invalid parameters: propertyId', propertyId, 'from', from.toISOString(), 'to', to.toISOString()); - return Promise.reject('Invalid parameters: ' + typeof propertyId); + if (typeof propertyId !== 'number' || !from.isValid() || !to.isValid() || !validAggregateLevel) { + log.info('getValues: Invalid parameters: propertyId', propertyId, 'from', from.toISOString(), 'to', to.toISOString(), 'aggregateLevel', aggregateLevel); + return Promise.reject('Invalid parameters'); } else { log.info('getValues: propertyId', propertyId, 'from', from.toISOString(), 'to', to.toISOString()); - return dao.aggregateValuesByPropertyId(propertyId, 'hour', from.toDate(), to.toDate()); + return dao.aggregateValuesByPropertyId(propertyId, aggregateLevel, from.toDate(), to.toDate()); } } else { return dao.valuesByPropertyId(propertyId, limit); |