diff options
| author | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-27 00:03:48 +0000 |
|---|---|---|
| committer | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-27 00:03:48 +0000 |
| commit | 714368c049f8749ed22c6d1d07bb3adc783dc349 (patch) | |
| tree | 8952248ebf3f85b141ef0d18ecf6a1becdc8b89b /node_simple.js | |
| parent | 8beb37ed67b5f2fa0f9aa85499a8f11b39c9d067 (diff) | |
| parent | b65166302f5296165da115ed96ce112433157a2d (diff) | |
Merge branch 'master' of https://github.com/HumairAK/solutions_repo
Diffstat (limited to 'node_simple.js')
| -rw-r--r-- | node_simple.js | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/node_simple.js b/node_simple.js index cb9fcf1..8bce9a0 100644 --- a/node_simple.js +++ b/node_simple.js @@ -599,7 +599,6 @@ exports.retrieveUser = function (username, callback) { } else if (result.length) { - console.log("retreive User: " + result[0]); callback(true, false, result[0], "User retrieved"); } @@ -777,29 +776,36 @@ exports.add_comment = function (sol_id, fields, serverCallback) { * @param {function} callback: <[Objs]> - RESULT * */ exports.get_all_solutions = function (exam_id, q_num, callback) { - mongoFactory.getConnection(uri) - .then(function (db) { - var solutions = db.collection('solutions'); + // check if the exam id already exists... + exports.get_exam_byID(exam_id, function (success, failure, exam) { + if (!success && failure) { // some error occurred while searching + callback(false, true, "Error: Some error occurred while searching for exam", null); + } else if (!success && !failure) { + callback(false, true, "Error: this exam doesn't exist", null); + } else if (success && !failure) { // this exam exists proceed with task + mongoFactory.getConnection(uri).then(function (db) { - solutions.find( - { - exam_id: exam_id, - q_id: q_num - } - ).sort({ votes: -1}).toArray( function (err, docs) { - if (err) throw err; - else { - callback(docs); - } + var solutions = db.collection('solutions'); - }); + solutions.find( + { + exam_id: exam_id, + q_id: q_num + } + ).sort({ votes: -1}).toArray( function (err, docs) { + if (err) callback(false, true, "Error: Some error occurred while looking for solutions"); + else { // either nothing was found or something was found + callback(true, false, "Solutions", docs); + } + }); + }).catch(function () { + callback(false, true, "Error: Some error occurred with the db connection", null); + }) + } + }); - }) - .catch(function () { - console.error(err); - }) }; /** @@ -1229,7 +1235,6 @@ exports.get_exam_byID = function (id, callback) { } else { callback(true, false, docs[0]); - console.log("DOCS: "+ docs); } }); }) |
