aboutsummaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
authornanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-24 00:56:53 +0000
committernanalelfe <nargiza.nosirova@mail.utoronto.ca>2016-07-24 00:56:53 +0000
commit39afbefe2ea5b7a105c352049a4a4a171502e880 (patch)
treec973111431d2f69bae4a7be57f05fd3a773da94f /routes
parentdbdcb21969ffd5540bd310b14ee2348adac24b5c (diff)
parent18b6e474fb64f7e9b4699d3bfbf3f5276e6996ad (diff)
Merged get_exam_byID
Diffstat (limited to 'routes')
-rw-r--r--routes/admin.js5
-rw-r--r--routes/index.js75
2 files changed, 63 insertions, 17 deletions
diff --git a/routes/admin.js b/routes/admin.js
index 5aa22fe..7e5c7fe 100644
--- a/routes/admin.js
+++ b/routes/admin.js
@@ -8,8 +8,6 @@ var passport_file = require('../config/passport.js');
var csrfProtection = csrf();
router.use(csrfProtection); // router is protected
-
-
router.get('/', isAdmin, function(req,res){
res.render('admin', {csrfToken: req.csrfToken()});
});
@@ -65,7 +63,7 @@ router.post('/add/course', function(req,res){
res.redirect('/admin');
});
-// Add a new admin, redirect to admin panel
+/* Add a new admin, redirect to admin panel */
router.post('/add/admin', function(req,res){
var admin_data = {
fname: req.body.fname,
@@ -128,7 +126,6 @@ module.exports = router;
/************** Route protection ********************/
-
function isAdmin(req, res, next) {
if (req.user && !req.user.email){
return next();
diff --git a/routes/index.js b/routes/index.js
index 4a0e54c..d3c55e6 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -84,24 +84,73 @@ router.get('/search', function(req, res, next) {
res.redirect('/exams/' + courseName);
});
-/*EXAMPLE DATA GIVEN BELOW:
+
+/* This is a redirect from the exams page, route is generated in exams.hbs
+ *
+ * EXAMPLE DATA GIVEN BELOW:
* questions = [{id,count,comments},{id,count,comments}] --> array of "question" objects
*
* id = questions number
* count= number of solutions
* comments = number of comments*/
router.get('/questions/:exam_id', function (req,res) {
- console.log(req.params.exam_id);
- dbFile.get_exam_info_by_ID(req.params.exam_id, function (questions) {
+ var examID = req.params.exam_id;
+ console.log(examID);
+ dbFile.get_exam_byID(examID, function(exam){
+
+ /* [
+ { q_id: 1, question: 'this is q1' },
+ { q_id: 2, question: 'this is q2' }
+ ]
+ */
+ var qList = exam.questions_list;
+
+ // Add comments/solutions
+ dbFile.get_exam_info_by_ID(examID, function (questionsInfo) {
+ qList.forEach(function(question){
+ question.count = 0;
+ question.comments = 0;
+
+ // Find q_id in questionsInfo, update comment/solutions count
+ questionsInfo.forEach(function(q){
+ if (q.id == question.id){
+ question.count += q.count;
+ question.comments += q.comments;
+ }
+ });
+ });
+
+ var examInfo = {
+ id : exam._id,
+ courseCode : exam.course_code,
+ term : toProperCase(exam.term),
+ type : toProperCase(exam.type),
+ year : exam.year,
+ instructors : exam.instructors.join(),
+ uploadDate : exam.upload_date,
+ uploader : exam.uploaded_by,
+ pageCount : exam.page_count,
+ questionCount : exam.questions_count
+ };
+ res.render('questions', {query: qList, examInfo: examInfo});
+ });
+
+
+ console.log(exam);
+ });
+
+ /*dbFile.get_exam_info_by_ID(examID, function (questions) {
console.log(questions);
res.render('questions', {query: questions});
- });
+ });*/
+
});
-/*GET the solutions for a given exam given the question number and the exam_id*/
-/*EXPECTED DATA GIVEN BELOW:
-array of solutions:
+/*GET the solutions for a given exam given the question number and the exam_id
+
+* EXPECTED DATA GIVEN BELOW:
+* array of solutions:
* solutions = [ {
* _id: "354ff71ed078933079d6467e"
* exam_id: "578a44ff71ed097fc3079d6e"
@@ -112,17 +161,17 @@ array of solutions:
* }
* {
* _id: ...
- * exam_id: ..
- * q_id: ...
- * text: ..
- * votes: ..
- * comments: ..
+ * exam_id: ..
+ * q_id: ...
+ * text: ..
+ * votes: ..
+ comments: ..
*
* }
* ]*/
router.get('/solutions/:exam_id/:q_num', function (req, res) {
dbFile.get_all_solutions(req.params.exam_id,req.params.q_num,function (solutions) {
- res.render('solutions', {query: solutions});
+ res.render('user_solutions', {query: solutions});
console.log(solutions);
});
});