forked from owen28299/nasa_aircheck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
69 lines (60 loc) · 1.65 KB
/
server.js
File metadata and controls
69 lines (60 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
const express = require('express'),
app = express(),
bodyParser = require('body-parser'),
db = require('./models'),
apiRoute = require('./routes/apiRoute.js'),
searchRoute = require('./routes/searchRoute.js'),
User = db.User
;
app
.use(bodyParser.urlencoded({extended: true}))
.use(bodyParser.json())
.use(express.static('public'))
.use('/api', apiRoute)
.use('/search', searchRoute)
.listen(3000, function() {
db.sequelize.sync();
console.log('server started at 3000!');
})
;
app.get('/allUsers/:city', function(req,res){
db.sequelize.query(`SELECT * FROM "Users" WHERE location='` + req.params.city + `'`)
.then(function(users){
var conditions = {
coughing : 0,
sneezing : 0,
itchyeyesandnose : 0,
sorethroat : 0,
shortnessofbreath : 0,
wateryeyes : 0,
stuffynose : 0
};
users[0].forEach(function(element){
for (var prop in element){
if( conditions.hasOwnProperty(prop) ) {
conditions[prop] += element[prop];
}
}
});
res.json(conditions);
});
});
app.post('/newUser', function(req,res){
// console.log(req.body);
User.create({
location : req.body.city,
coughing : req.body.coughing,
sneezing : req.body.sneezing,
itchyeyesandnose : req.body.itchyeyesandnose,
sorethroat : req.body.sorethroat,
shortnessofbreath : req.body.shortnessofbreath,
wateryeyes : req.body.wateryeyes,
stuffynose : req.body.stuffynose,
createdAt : new Date(),
updatedAt : new Date()
})
.then(function(){
res.redirect("/");
});
});