forked from sf-wdi-25/express_self_api
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathbjjControllers.js
More file actions
55 lines (38 loc) · 1.06 KB
/
bjjControllers.js
File metadata and controls
55 lines (38 loc) · 1.06 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
var db = require('../models');
function index(req, res) {
db.Bjj.find({}, function(err, allAlbums) {
res.json(allAlbums);
});
}
// create function to create data in database
function create(req, res) {
console.log('body', req.body);
db.Bjj.create(req.body, function(err, reviews) {
console.log(reviews);
if (err) { console.log('error', err); }
console.log(reviews);
res.json(reviews);
});
}
// get data input by id
function show(req, res) {
// find one gym by id and send it back as JSON
console.log(req.params.bjjId);
db.Bjj.findById(req.params.bjjId, function(err, foundAlbum) {
if(err) { console.log('albumsController.show error', err); }
console.log('albumsController.show responding with', foundAlbum);
res.json(foundAlbum);
});
}
function destroy(req, res) {
db.Bjj.findByIdAndRemove({_id: req.params.bjjId}, (err, response) => {
res.status(200).send(response);
console.log("shit did work: buh bye")
});
}
module.exports = {
index: index,
create: create,
show: show,
destroy: destroy
}