forked from mauriciodeoliveirareis/CityBuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanswerDao.js
44 lines (36 loc) · 1.19 KB
/
answerDao.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
var monk = require ("monk");
var db = monk ("mongodb://IbmCloud_1140l45k_8qs5ds2q_sufis1th:[email protected]:41190/IbmCloud_1140l45k_8qs5ds2q");
var putAnswer = function(answerData, callback) {
var answerCol = db.get("answer");
answerData.timestamp = new Date().getTime();
answerCol.insert(answerData, function (error, response) {
callback(response);
});
};
var getAnswers = function(filter, callback) {
var answerCol = db.get("answer");
console.log("printing the filter for the getAnswers:");
console.log(filter);
var filterJson = {};
if(filter){
if(filter.question_id) {
filterJson.question_id = filter.question_id;
}
if(filter.category) {
filterJson.category = filter.category;
}
}
console.log(filterJson);
answerCol.find(filterJson, {sort : { timestamp : -1 }}, function (error, answersList) {
callback(answersList);
});
};
var deleteAnswers = function(filter, callback) {
var answerCol = db.get("answer");
answerCol.drop(function (error, answersList) {
callback(answersList);
});
};
module.exports.putAnswer = putAnswer;
module.exports.getAnswers = getAnswers;
module.exports.deleteAnswers = deleteAnswers;