-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathapi.js
41 lines (37 loc) · 1000 Bytes
/
api.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
var express = require('express');
var mongoose = require('mongoose');
var router = express.Router();
/* display game. */
router.get('/game/:id', function(req, res) {
var id = req.params.id;
mongoose.model('Game').findById(id, function(err, game) {
if(err) {
res.status(500).end();
}
if (game == null){
res.status(404).end();
} else {
res.send(game);
}
});
});
/* display user. */
router.get('/user/:name', function(req, res) {
var name = req.params.name;
mongoose.model('User').findOne({name: name}, function(err, user) {
if(err) {
res.status(500).end();
}
if (user == null){
res.status(404).end();
} else {
res.send({
id: user._id,
name: user.name,
email: user.email,
lastConnection: user.lastConnection
});
}
});
});
module.exports = router;