diff options
| author | HumairAK <humair88@hotmail.com> | 2016-07-25 07:40:26 +0000 |
|---|---|---|
| committer | HumairAK <humair88@hotmail.com> | 2016-07-25 07:40:26 +0000 |
| commit | 3d9c04b336c0eade0e15517c0144f44f12ba865f (patch) | |
| tree | 20af91e006115fdd98731d5fed2c0eebbbc29810 | |
| parent | 1032205c1a94ae31d780d2c339abbe628eb27fae (diff) | |
Accounted for empty comment history in retrieve_userComments_history
| -rw-r--r-- | node_simple.js | 22 | ||||
| -rw-r--r-- | routes/user.js | 1 |
2 files changed, 14 insertions, 9 deletions
diff --git a/node_simple.js b/node_simple.js index 0290519..f7da2c3 100644 --- a/node_simple.js +++ b/node_simple.js @@ -350,16 +350,20 @@ exports.retrieve_userComments_history = function (username, callback) { _id: 0 }} ]).toArray(function (err, res) { - 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(); + 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() { diff --git a/routes/user.js b/routes/user.js index b179236..7a3e27c 100644 --- a/routes/user.js +++ b/routes/user.js @@ -51,6 +51,7 @@ router.get('/user_profile', loggedIn, isUser, function(req, res, next) { } function getMail(){ return new Promise(function(resolve, reject) { + dbFile.checkMailbox(req.user.user_name, function(success, error, data, message){ if (success) { inbox = data; |
