From 38594fd274a4bebee75ae71dbed457b39d253cae Mon Sep 17 00:00:00 2001 From: HumairAK Date: Tue, 26 Jul 2016 20:18:22 -0400 Subject: fixed false exam path search for solutions, minor change to db function --- node_simple.js | 4 ++-- routes/index.js | 17 +++++++++++------ test/routingDb_tests.js | 2 +- views/error.hbs | 9 ++++++++- views/questions.hbs | 2 +- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/node_simple.js b/node_simple.js index 008cf81..50d8469 100644 --- a/node_simple.js +++ b/node_simple.js @@ -782,7 +782,7 @@ exports.get_all_solutions = function (exam_id, q_num, callback) { 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); + callback(false, true, "Error: this exam does not exist", null); } else if (success && !failure) { // this exam exists proceed with task mongoFactory.getConnection(uri).then(function (db) { @@ -1230,7 +1230,7 @@ exports.get_exam_byID = function (id, callback) { exams.find( {_id: ObjectId(id)} ).toArray(function (err, docs) { if (err) { callback(false, true, null); - } else if (!docs) { + } else if (docs.length == 0) { callback(false, false, null); } else { diff --git a/routes/index.js b/routes/index.js index f8292fc..219b7b7 100644 --- a/routes/index.js +++ b/routes/index.js @@ -232,12 +232,17 @@ router.get('/questions/:exam_id', function (req,res) { router.get('/solutions/:exam_id/:q_num', function (req, res) { var examID = req.params.exam_id; var qID = req.params.q_num; - dbFile.get_all_solutions(examID, qID, function (solutions) { - solutions.forEach(function(soln){ - soln.commentCount = soln.comments.length; - }); - res.render('user_solutions', {query: solutions, examID: examID, qID: qID, csrfToken: req.csrfToken()}); - req.session.messages = null; + dbFile.get_all_solutions(examID, qID, function (success, failure, message, solutions) { + if(success){ + solutions.forEach(function(soln){ + soln.commentCount = soln.comments.length; + }); + res.render('user_solutions', {query: solutions, examID: examID, qID: qID, csrfToken: req.csrfToken()}); + req.session.messages = null; + } else{ + res.render('error', {error : message}); + } + }); }); diff --git a/test/routingDb_tests.js b/test/routingDb_tests.js index 998d34a..dd5fe44 100644 --- a/test/routingDb_tests.js +++ b/test/routingDb_tests.js @@ -13,7 +13,7 @@ var fs = require('fs'); * To run test simply type $mocha in the terminal. Ensure preconditions listed * below are met. Due to db queries, if tests fail due to time out, increase * the time out flag in mocha.opts for --timeout. - * + * */ /* PRE-CONDITION: * diff --git a/views/error.hbs b/views/error.hbs index 062b947..cb2db5d 100644 --- a/views/error.hbs +++ b/views/error.hbs @@ -1,5 +1,12 @@
diff --git a/views/questions.hbs b/views/questions.hbs index 48248c2..4b40d33 100644 --- a/views/questions.hbs +++ b/views/questions.hbs @@ -3,7 +3,7 @@ - +

{{examInfo.courseCode}}

-- cgit v1.2.3