aboutsummaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-03-06 21:48:19 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2016-03-06 21:48:19 +0100
commit681cd42eda3b1099f13eefa585673a06f12de405 (patch)
treee26f7674d6a9e7a027462d960b6e2917a2f2b4fe /src/web
parent45267e41368fbb9fb318fb455981110e83c97953 (diff)
downloaddiller-server-681cd42eda3b1099f13eefa585673a06f12de405.tar.gz
diller-server-681cd42eda3b1099f13eefa585673a06f12de405.tar.bz2
diller-server-681cd42eda3b1099f13eefa585673a06f12de405.tar.xz
diller-server-681cd42eda3b1099f13eefa585673a06f12de405.zip
core:
o Supporting aggregate levels of 'minute' and 'day' in addition to the existing 'hour'.
Diffstat (limited to 'src/web')
-rw-r--r--src/web/DillerWeb.js11
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);