-
Notifications
You must be signed in to change notification settings - Fork 1
/
routes.js
83 lines (67 loc) · 2.62 KB
/
routes.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var fs = require('fs');
var users = require('./services/users');
var schedule = require('./services/schedule');
var classics = require('./services/classics');
var teams = require('./services/teams');
var statuses = require('./services/statuses');
var notifications = require('./services/notifications');
var Session = require('./models/Session');
var stringCompare = function(a, b) {
if (a < b) {
return -1;
}
else if (a > b) {
return 1;
}
else {
return 0;
}
};
module.exports = function(app) {
app.get('/', schedule.showAllForDate);
app.get('/preview', function(request, response) {
response.cookie('gateKey', process.env.GATE_KEY).redirect('/');
});
app.get('/unpreview', function(request, response) {
response.clearCookie('gateKey').redirect('/');
});
app.get('/login', users.loginPrompt);
app.get('/users', users.showAll);
app.get('/users.json', users.all);
app.get('/users/add', users.add);
app.post('/users/add', users.signUp);
app.get('/users/edit/:username', users.edit);
app.post('/users/edit/:username', users.update);
app.get('/schedule/?', schedule.showAllForDate);
app.get('/schedule.json', schedule.allForDate);
app.get('/schedule/:date(\\d\\d\\d\\d-\\d\\d-\\d\\d)', schedule.showAllForDate);
app.get('/schedule/:teamAbbreviation(\\w+)', schedule.showAllForTeam);
app.get('/picks', classics.showAllForUser);
app.get('/picks.json', classics.all);
app.get('/picks/:teamAbbreviation([A-Z][A-Z][A-Z]?)', classics.showAllForTeam);
app.get('/picks/:username([a-z-]+)', classics.showAllForUser);
app.get('/picks/:username([a-z-]+).json', classics.allForUser);
app.get('/pick/:teamId/:gameId', classics.pick);
app.get('/unpick/:teamId/:gameId', classics.unpick);
app.get('/standings', classics.showStandings);
app.get('/standings/:season', classics.showStandings);
app.get('/teams', teams.showAll);
app.get('/statuses', statuses.showAll);
app.get('/notifications', notifications.showAll);
app.get('/notifications/dismiss/:notificationId', notifications.dismiss);
app.get('/report', function(request, response) {
fs.readFile('./data/report.json', 'utf8', (error, data) => {
var reportData = JSON.parse(data);
reportData.users.sort((a, b) => stringCompare(a.displayName, b.displayName));
reportData.teams.sort((a, b) => stringCompare(a.abbreviation, b.abbreviation));
Session.withActiveSession(request, function(error, session) {
response.render('report', { session: session, reportData: reportData });
});
});
});
app.get('/rules', function(request, response) {
Session.withActiveSession(request, function(error, session) {
response.render('rules', { session: session });
});
});
};