forked from slu-cs/project-finalproject-charlieamberconner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.js
60 lines (44 loc) · 1.54 KB
/
router.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
const express = require('express');
const users = require('./controllers/users');
const lists = require('./controllers/lists');
const router = express.Router();
// Check for admin status
const authorize = function(request, response, next) {
if (request.session.user) {
next(); // Fulfill the request
} else {
response.status(401).end();
}
};
// Handle home-page requests
router.get('/', function(request, response) {
response.render('index');
});
// handle create page requests
router.get('/create', function(request, response) {
response.render('create');
});
// create new user
router.post('/users', users.create);
// Handle login requests
router.post('/login', users.login);
// Handle logout requests
router.get('/logout', function(request, response) {
request.session.user = undefined;
response.redirect('/');
});
// handle user requests
router.get('/users', authorize, users.index);
router.get('/users/:id', authorize, users.retrieve);
// Handle list requests
router.get('/lists', authorize, lists.index);
router.get('/lists/unclaimed', authorize, lists.unclaimed);
router.get('/lists/myclaimed', authorize, lists.myclaimed);
router.get('/lists/mylists', authorize, lists.mylists);
// Handle getting lists by id, my claimed lists, and my lists
router.get('/lists/:id', authorize, lists.retrieve);
router.put('/lists/:id', authorize, lists.claim);
router.post('/lists', authorize, lists.create);
router.delete('/lists/:id', authorize, lists.delete);
router.post('/comments/:id', authorize, lists.comment);
module.exports = router;