Skip to content

Commit

Permalink
[feat] Add another function to get the time of the most recent data
Browse files Browse the repository at this point in the history
  • Loading branch information
seblucas committed Jan 9, 2019
1 parent 4f7d6e3 commit 42c1829
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,19 @@ exports.monitor = functions.https.onRequest((req, res) => {
res.sendStatus(500);
});
});

exports.lastupdated = functions.https.onRequest((req, res) => {
console.log(req.query.r);
admin.database().ref('/readings/' + req.query.r).limitToLast(1).once('value').then(snapshots => {
res.set('Cache-Control', 'private, max-age=300');
let time = 0;
snapshots.forEach(snapshot => {
var currentData = snapshot.val();
time = currentData.time;
});
return res.status(200).send(time.toString());
}).catch(error => {
console.error('Error while getting sensor detail', error.message);
res.sendStatus(500);
});
});

0 comments on commit 42c1829

Please sign in to comment.