-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.js
54 lines (46 loc) · 1.66 KB
/
controller.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
var Q = require('q');
var Controller = function(adapter, responder){
this.adapter = adapter
this.responder = responder
}
Controller.prototype.index = function(req, res) {
var context = this
context.adapter.index(req, res, Q.defer())
.then(function (molecule) {
context.responder.set(molecule, Q.defer()).then(context.responder.index(req, res)).done()
})
.done()
}
Controller.prototype.search = function(req, res) {
var context = this
context.adapter.search(req, res, Q.defer())
.then(function (molecule) {
context.responder.set(molecule, Q.defer()).then(context.responder.index(req, res)).done()
})
.done()
}
Controller.prototype.show = function(req, res) {
var context = this
context.adapter.show(req, res, Q.defer())
.then(function(molecule){
context.responder.set(molecule, Q.defer()).then(context.responder.show(req, res)).done()
})
.done()
}
Controller.prototype.create = function(req, res) {
var context = this
context.adapter.create(req, res, Q.defer()).then(function(path){context.responder.redirect(res, path)}).done()
}
Controller.prototype.update = function(req, res) {
var context = this
context.adapter.update(req, res, Q.defer())
.then(function(molecule){
context.responder.set(molecule, Q.defer()).then(context.responder.show(req, res)).done()
})
.done()
}
Controller.prototype.destroy = function(req, res) {
var context = this
context.adapter.destroy(req, res, Q.defer()).then(function(path){context.responder.redirect(res, path)}).done()
}
exports.Controller = Controller