diff options
| author | kumar <kumar.damani@mail.utoronto.ca> | 2016-07-24 00:57:36 +0000 |
|---|---|---|
| committer | kumar <kumar.damani@mail.utoronto.ca> | 2016-07-24 00:57:36 +0000 |
| commit | 8f6bfa9244411274c4f6a489b2571a423f7d8548 (patch) | |
| tree | e75f85ee2cfd65190acda7e8494ca6c736f5aa1b /node_simple.js | |
| parent | fe51deb31bbcc90530617b2b8aa60caf17c76729 (diff) | |
| parent | 39afbefe2ea5b7a105c352049a4a4a171502e880 (diff) | |
pull
Merge branch 'master' of https://github.com/HumairAK/solutions_repo
Diffstat (limited to 'node_simple.js')
| -rw-r--r-- | node_simple.js | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/node_simple.js b/node_simple.js index 26cbbe4..58a114b 100644 --- a/node_simple.js +++ b/node_simple.js @@ -158,6 +158,10 @@ exports.retrieveFollows = function (user_name, callback) { // will add comments ASAP +/* callback(success, data/message) => callback(boolean, object/String); + * + * + */ exports.retrieve_userComments_history = function (username, callback) { // get a connection @@ -180,7 +184,7 @@ exports.retrieve_userComments_history = function (username, callback) { _id: 0 }} ]).toArray(function (err, results) { - if (err) callback(false, "Error: some wierd error occured while query"); + if (err) callback(false, "Error: some weird error occurred while query"); else { callback(true, results); } @@ -198,7 +202,7 @@ exports.retrieve_userComments_history = function (username, callback) { exports.retrieve_userComments_count = function (username, callback) { exports.retrieve_userComments_history(username, function (bool, results) { - if (!bool) callback(false, "Error: error occured"); + if (!bool) callback(false, "Error: error occurred"); else { var length = results.length; callback(true, length); @@ -891,9 +895,8 @@ exports.remove_exam = function (fields, serverCallback) { }); }; -//get_exam_byID("578a44ff71ed097fc3079d6e"); - -exports.get_exam_byID = function (id, serverCallback) { +// callback(success, error, data) +exports.get_exam_byID = function (id, callback) { // establish a connection mongoFactory.getConnection(uri) @@ -903,15 +906,19 @@ exports.get_exam_byID = function (id, serverCallback) { var exams = db.collection('exams'); // query exams.find( {_id: ObjectId(id)} ).toArray(function (err, docs) { - if (err) throw err; + if (err) { + callback(false, true, null); + } else if (!docs) { + callback(false, false, null); + } else { - serverCallback(docs[0]); - //console.log(docs); + callback(true, false, docs[0]); + } }); }) .catch(function(err) { - console.error(err); + callback(false, true, null); }); }; |
