-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-file.js
49 lines (44 loc) · 1.08 KB
/
test-file.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
var router = express.Router();
var leaderboard = require('../public/leaderboard.json');
router.get('/all', function (req, res) {
console.log(leaderboard.length);
return res.json(leaderboard);
});
router.get('/stud/:rank', function (req, res) {
if(leaderboard[req.params.rank]){
return res.json(leaderboard[req.params.rank]);
}
return res.status(404).json({
message: 'not found',
error: true,
});
});
router.post('/stud', function (req, res) {
if(!req.body.Name || !req.body.College){
return res.json({
message: 'not formatted properly',
error: true,
data: req.body
});
}
var stud = req.body;
leaderboard.push(stud);
return res.json({
message: 'Success!',
error: false
});
});
router.delete('/stud/:rank', function (req, res) {
if(leaderboard[req.params.rank]){
console.log('Deleting - ' + leaderboard[req.params.rank].Name);
leaderboard.pop(req.params.rank);
return res.json({
message: 'Success!',
error: false
});
}
return res.status(404).json({
message: 'not found',
error: true,
});
});