-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (52 loc) · 1.49 KB
/
index.js
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
const express = require('express');
const bodyparser = require('body-parser');
const path = require('path');
const model = require('./model');
const config = require('./config');
const app = express();
const PORT = process.env.PORT || 3000;
app.set('views', './public/views');
app.set('view engine', 'pug');
app.use(express.static(path.join(__dirname, 'public')));
app.use(bodyparser.json());
app.use(bodyparser.urlencoded({extended: false}));
app.get('/', (req, res) => {
res.render('index');
});
app.get('/user/:user', (req, res) => {
const user = req.params.user;
console.log(user + ' is trying to access the system.');
if (user !== config.systemUser) {
res.render('error');
} else {
model.getChildHours(req, res);
}
});
app.get('/user/update/:name', (req, res) => {
const name = req.params.name;
const hours = [
req.query.reading,
req.query.language,
req.query.math,
req.query.history,
req.query.science,
req.query.art,
req.query.music,
req.query.bible,
req.query.pe,
req.query.life,
req.query.core,
req.query.noncore,
req.query.total,
name
];
console.log('Updating child: ' + name + ' with params: ' + hours.toString());
model.updateChildHours(req, res, hours, name);
});
app.listen(PORT, (err) => {
if (err) {
throw new Error();
} else {
console.log('Homeschool Tracker app is listening on port: ' + PORT);
}
});