-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestionController.js
More file actions
67 lines (53 loc) · 1.25 KB
/
Copy pathquestionController.js
File metadata and controls
67 lines (53 loc) · 1.25 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
var Qs = require('./questionModel.js');
var Q = require('q');
var findQ = Q.nbind(Qs.findOne, Qs);
var findAll = Q.nbind(Qs.find, Qs);
var createQ = Q.nbind(Qs.create, Qs);
module.exports = {
all : function(req, res, next) {
findAll({}).then(function (qs) {
//console.log("Find all Qs", qs);
res.json(qs);
})
.fail(function (error) {
next(error);
});
},
newQ : function(req, res, next) {
console.log('Add new question - server', req.body.text);
var newQ = {
text: req.body.text,
ups: 0,
downs: 0
};
createQ(newQ).then(function (newq) {
console.log("New question created", newq);
res.json(newq);
})
.fail(function (error) {
next(error);
});
},
thumbUp: function(req, res, next) {
findQ({text:req.body.text}).then(function (qs) {
console.log("Thumb Up - server", qs);
qs.ups++;
qs.save(function (err, savedQ) {
if (err) {
next(err);
}
});
});
},
thumbDown: function(req, res, next) {
findQ({text:req.body.text}).then(function (qs) {
console.log("Thumb Down - server", qs);
qs.downs++;
qs.save(function (err, savedQ) {
if (err) {
// next(err);
}
});
});
},
};