-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocuments.js
60 lines (50 loc) · 1.66 KB
/
documents.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
50
51
52
53
54
55
56
57
58
59
60
"use strict";
function Controller (){
}
module.exports = Controller;
Controller.prototype = {
"@Path": "/documents",
init: function(Document)/*@Autowired @PostConstruct*/{
this.Document = Document;
},
editDocument: function(/*@Callback*/_return, /*@Param*/id) /*@GET("/:id/edit")*/ {
this.Document.findById(id, function(err, doc){
_return({view:'documents/edit', model:{d:doc}});
});
},
newDocument: function() /*@GET("/new")*/ {
return {view:'documents/new', model:{d:{title:'New Document'}}};
},
listDocuments: function(/*@Callback*/_return) /*@GET("/") @Auth*/ {
this.Document.find(function (err, docs){
if (err) console.error(err);
_return({view:'documents/index', model:{documents:docs}});
});
},
getDocument: function(/*@Callback*/_return, /*@Param*/id) /*@GET("/:id") @JSON*/ {
this.Document.findOne({'_id': id}, function (err, docs){
if (err) console.error(err);
_return(docs);
});
},
createNewDocument: function(/*@Callback*/_return, /*@Body*/newDoc) /*@POST("/") @JSON*/ {
var persDoc = new this.Document(newDoc);
persDoc.save(function (err, d){
if (err) console.error(err);
_return(d);
});
},
deleteDocument: function(/*@Callback*/_return, /*@Param*/id) /*@DELETE("/:id") @JSON*/ {
this.Document.remove({'_id': id}, function(err){
if (err) console.error(err);
_return(null);
});
},
updateDocument: function(/*@Callback*/_return, /*@Param*/id, /*@Body*/newDoc) /*@PUT("/:id") @JSON*/ {
this.Document.findByIdAndUpdate(id, newDoc, function(err, d){
if (err) console.error(err);
//_return("redirect:documents/");
_return(d);
});
}
};