-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweeks.js
More file actions
73 lines (55 loc) · 1.81 KB
/
Copy pathweeks.js
File metadata and controls
73 lines (55 loc) · 1.81 KB
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
// on routes that end in /types
// ----------------------------------------------------
router.route('/types')
// create a type (accessed at POST http://localhost:8080/types)
.post(function(req, res) {
var type = new type(); // create a new instance of the type model
type.name = req.body.name; // set the types name (comes from the request)
type.save(function(err) {
if (err)
res.send(err);
res.json({ message: 'type created!' });
});
})
// get all the types (accessed at GET http://localhost:8080/api/types)
.get(function(req, res) {
type.find(function(err, types) {
if (err)
res.send(err);
res.json(types);
});
});
// on routes that end in /types/:person_id
// ----------------------------------------------------
router.route('/types/:person_id')
// get the type with that id
.get(function(req, res) {
type.findById(req.params.person_id, function(err, type) {
if (err)
res.send(err);
res.json(type);
});
})
// update the type with this id
.put(function(req, res) {
type.findById(req.params.person_id, function(err, type) {
if (err)
res.send(err);
type.name = req.body.name;
type.save(function(err) {
if (err)
res.send(err);
res.json({ message: 'type updated!' });
});
});
})
// delete the type with this id
.delete(function(req, res) {
type.remove({
_id: req.params.person_id
}, function(err, type) {
if (err)
res.send(err);
res.json({ message: 'Successfully deleted' });
});
});