diff options
| author | HumairAK <humair88@hotmail.com> | 2016-07-27 00:18:22 +0000 |
|---|---|---|
| committer | HumairAK <humair88@hotmail.com> | 2016-07-27 00:18:22 +0000 |
| commit | 38594fd274a4bebee75ae71dbed457b39d253cae (patch) | |
| tree | 52600020d82067ed66975f137c9ce7920a83aa90 | |
| parent | b65166302f5296165da115ed96ce112433157a2d (diff) | |
fixed false exam path search for solutions, minor change to db function
| -rw-r--r-- | node_simple.js | 4 | ||||
| -rw-r--r-- | routes/index.js | 17 | ||||
| -rw-r--r-- | test/routingDb_tests.js | 2 | ||||
| -rw-r--r-- | views/error.hbs | 9 | ||||
| -rw-r--r-- | 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 @@ <main id = 'solutions-main'> <div class = 'search container' id = 'solutions-div'> - <h4>Sorry, we could not find {{ url }}</h4> + {{# if url}} + <h4>Sorry, we could not find {{ url }}</h4> + {{/if}} + {{# if error }} + <section class="alert alert-danger custom-Alert"> + <h4>{{ error }}</h4> + </section> + {{/if}} </div> </main> 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 @@ <!-- EXAM DETAILS --> - <a href="http://www.cs.toronto.edu/~fpitt/CSC148/20131/tests/test1-0101.pdf" target='_blank'><img src="assets/images/exam.png" class='exam-img img-responsive exam-info'></a> + <a href="http://www.cs.toronto.edu/~fpitt/CSC148/20131/tests/test1-0101.pdf" target='_blank'><img src="/assets/images/exam.png" class='exam-img img-responsive exam-info'></a> <section class='exam-info'> <h3>{{examInfo.courseCode}}</h3> |
