aboutsummaryrefslogtreecommitdiff
path: root/node_simple.js
diff options
context:
space:
mode:
authornanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-25 07:50:45 +0000
committernanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-25 07:50:45 +0000
commit908de8f330759e5c3866089f9efd210a5a884042 (patch)
tree188035ba080946b8888b08932bc9d5a605d714e3 /node_simple.js
parentbadc34373b4e474d9bf443e36e6bbe5669eb9556 (diff)
parent3d9c04b336c0eade0e15517c0144f44f12ba865f (diff)
Update
Diffstat (limited to 'node_simple.js')
-rw-r--r--node_simple.js24
1 files changed, 13 insertions, 11 deletions
diff --git a/node_simple.js b/node_simple.js
index 426570a..2eab34c 100644
--- a/node_simple.js
+++ b/node_simple.js
@@ -350,18 +350,20 @@ exports.retrieve_userComments_history = function (username, callback) {
_id: 0
}}
]).toArray(function (err, res) {
- console.log("for Each here");
- var finised = _.after(res.length, doCall); // execute "doCall" only after res.length # of attempts
- res.forEach(function (comment) {
- console.log("for Each here");
- exams.find( { _id: ObjectId(comment.exam_id) } ).toArray(function (err, docs) { // get the exam info
- comment.course_code = docs[0].course_code;
- comment.year = docs[0].year;
- comment.term = docs[0].term;
- mylist.push(comment); // save it to array
- finised();
+ if(!res.length){ // Ensure a callback is executed if res is empty
+ callback(true, res);
+ }else{
+ var finised = _.after(res.length, doCall); // execute "doCall" only after res.length # of attempts
+ res.forEach(function (comment) {
+ exams.find( { _id: ObjectId(comment.exam_id) } ).toArray(function (err, docs) { // get the exam info
+ comment.course_code = docs[0].course_code;
+ comment.year = docs[0].year;
+ comment.term = docs[0].term;
+ mylist.push(comment); // save it to array
+ finised();
+ });
});
- });
+ }
});
function doCall() {