aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkumar <kumar.damani@mail.utoronto.ca>2016-07-26 23:36:48 +0000
committerkumar <kumar.damani@mail.utoronto.ca>2016-07-26 23:36:48 +0000
commit248a428bace05c9b345128e96fa134a56eeabcdc (patch)
tree7e0f29a97dc74370dc79ce402ed3e0ee4071d3ac
parenta546c76d5eb8dcf2efe8b305cdb997b64914728e (diff)
added checking for examid before looking for its solutions
-rw-r--r--node_simple.js45
1 files changed, 27 insertions, 18 deletions
diff --git a/node_simple.js b/node_simple.js
index 1260c40..ca20978 100644
--- a/node_simple.js
+++ b/node_simple.js
@@ -776,27 +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");
+ })
+ }
+ });
- });
- })
- .catch(function () {
- console.error(err);
- })
};
/**