From 9c10936cf1420f160a5007c6baad7b25ffb6d014 Mon Sep 17 00:00:00 2001 From: HumairAK Date: Tue, 26 Jul 2016 16:44:06 -0400 Subject: Added more unit tests, fixed some bugs in the code, fixed voting alert prompts and redirects --- node_simple.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index 228e861..dced853 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"); } @@ -1229,7 +1228,6 @@ exports.get_exam_byID = function (id, callback) { } else { callback(true, false, docs[0]); - console.log("DOCS: "+ docs); } }); }) -- cgit v1.2.3 From 9f65445e7fcd5cc5d9d3183cb280b1ba13ac30b7 Mon Sep 17 00:00:00 2001 From: HumairAK Date: Tue, 26 Jul 2016 17:31:27 -0400 Subject: more unit tests --- node_simple.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index dced853..1260c40 100644 --- a/node_simple.js +++ b/node_simple.js @@ -793,8 +793,6 @@ exports.get_all_solutions = function (exam_id, q_num, callback) { } }); - - }) .catch(function () { console.error(err); -- cgit v1.2.3 From 248a428bace05c9b345128e96fa134a56eeabcdc Mon Sep 17 00:00:00 2001 From: kumar Date: Tue, 26 Jul 2016 19:36:48 -0400 Subject: added checking for examid before looking for its solutions --- node_simple.js | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'node_simple.js') 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); - }) }; /** -- cgit v1.2.3 From b65166302f5296165da115ed96ce112433157a2d Mon Sep 17 00:00:00 2001 From: kumar Date: Tue, 26 Jul 2016 19:40:23 -0400 Subject: minor bug fix --- node_simple.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'node_simple.js') diff --git a/node_simple.js b/node_simple.js index ca20978..008cf81 100644 --- a/node_simple.js +++ b/node_simple.js @@ -781,7 +781,7 @@ exports.get_all_solutions = function (exam_id, q_num, callback) { 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) { + } 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) { @@ -801,7 +801,7 @@ exports.get_all_solutions = function (exam_id, q_num, callback) { }); }).catch(function () { - callback(false, true, "Error: Some error occurred with the db connection"); + callback(false, true, "Error: Some error occurred with the db connection", null); }) } }); -- cgit v1.2.3