1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-12 02:42:48 +00:00

added more api's. Fixed data types for temperature schema

This commit is contained in:
2015-12-19 01:40:27 -06:00
parent 73da2b5020
commit da4140ddea
8 changed files with 100 additions and 21 deletions

View File

@@ -7,15 +7,13 @@ var temperature = mongoose.model('temperature');
/* GET sensors page. */
router.get('/tempsensors', function(req, res, next) {
router.get('/allsensors', function(req, res, next) {
//var location = req.query.location;
temperature.aggregate([ {$sort : {location : -1, updated : -1}},
{ $group : { _id : {location : "$location", month: {$month: "$updated" }, day: { $dayOfMonth: "$updated" }, year: { $year: "$updated" }},
max : {$max : "$temperature"},
min : {$min : "$temperature"}}}]).exec(function(err, info){
temperature.aggregate([{$group : { _id : {location : "$location", month: {$month: "$updated" }, day: { $dayOfMonth: "$updated" }, year: { $year: "$updated" }},
max : {$max : "$temperature"},
min : {$min : "$temperature"}}},
{$sort : {"_id.month" : -1, "_id.day" : -1, "_id.year" : -1}}]).exec(function(err, info){
console.log(info);
res.setHeader('Content-Type', 'application/json');
@@ -23,11 +21,25 @@ router.get('/tempsensors', function(req, res, next) {
});
});
router.get('/sensorbylocation', function(req, res, next) {
var loc = req.query.location;
console.log(loc);
//var location = req.query.location;
temperature.aggregate([ {$match : {location : loc}},
{$group : { _id : {location : "$location", month: {$month: "$updated" }, day: { $dayOfMonth: "$updated" }, year: { $year: "$updated" }},
max : {$max : "$temperature"},
min : {$min : "$temperature"}}},
{$sort : {"_id.month" : -1}}]).exec(function(err, info){
console.log(info);
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(info, null, 4));
});
});
router.post('/', function(req, res,next) {