-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.coffee
51 lines (26 loc) · 853 Bytes
/
resource.coffee
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
module.exports =
find: (req, res) ->
@model.find (err, data) ->
if not err then return res.json data
console.log err
get: (req, res) ->
@model.findById req.params.id, (err, data) ->
if not err then return res.json data
console.log err
put: (req, res) ->
@model.findById req.params.id, (err, data) ->
Object.keys(req.body).map (k) ->
data[k] = req.body[k]
data.save (err) ->
if not err then return res.json data
console.log err
post: (req, res) ->
model = new @model req.body
model.save (err) ->
if not err then return res.json model.toJSON()
console.log err
delete: (req, res) ->
@model.findById req.params.id, (err, data) ->
data.remove (err) ->
if not err then return res.json data
console.log err