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

started api

This commit is contained in:
2015-12-18 15:02:57 -06:00
parent fb06b22744
commit d299a8bdbb
2 changed files with 52 additions and 0 deletions

50
routes/api.js Normal file
View File

@@ -0,0 +1,50 @@
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
require("../models/temperature");
var temperature = mongoose.model('temperature');
/* GET sensors page. */
router.get('/tempsensors', function(req, res, next) {
var location = request.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){
console.log(info);
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(info, null, 4));
});
});
router.post('/', function(req, res,next) {
});
module.exports = router;