diff options
| author | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-20 21:11:59 +0000 |
|---|---|---|
| committer | nanalelfe <nargiza.nosirova@mail.utoronto.ca> | 2016-07-20 21:11:59 +0000 |
| commit | d46b37fcb7c97ab59fd929cfc0a8d766ca8a0b8a (patch) | |
| tree | 3b51e4c196bacd7c4524e8dbdb472a0e972aac8c /routes/index.js | |
| parent | 3d2f0e48def5b314121f7315ada1008f6801fa2b (diff) | |
| parent | 7a9c0a4732ba720fba72be06dcafa0dbbf26022b (diff) | |
Merged
Diffstat (limited to 'routes/index.js')
| -rw-r--r-- | routes/index.js | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/routes/index.js b/routes/index.js index 60a2c28..84087e7 100644 --- a/routes/index.js +++ b/routes/index.js @@ -33,9 +33,47 @@ router.get('/questions', function(req, res, next) { }); /* Render/GET exam page */ -router.get('/exams/:id', function(req, res, next) { +/* Render/GET exam page */ +//EXAMPLE EXPECTED DATA GIVEN BELOW: +/*[ { courseCode: 'CSC240', + year: 2016, + term: 'Fall', + instructors: [ 'Faith Ellen', 'Tom F.' ], + type: 'Midterm Examination', + title: 'Thry of Computation' }, + { courseCode: 'CSC240', + year: 2014, + term: 'Fall', + instructors: [ 'Faith Ellen', 'Tom F.' ], + type: 'Midterm Examination', + title: 'Thry of Computation' } ] + */ - res.render('exams', {query: req.params.id}); +router.get('/exams/:id', function(req, res, next) { + var minExamInfoArray = []; + dbFile.get_all_exams(req.params.id, function (exams) { + if (exams.length == 0){ + console.log("Nothing was found"); + } + else { + //console.log(exams); + //only pass over the information that is necessary for the exams page + for (var i = 0; i<exams.length;i++){ + var minExamInfo = { courseCode:exams[i].course_code, + year:exams[i].year, + term:toProperCase(exams[i].term), + instructors:exams[i].instructors, + type:toProperCase(exams[i].type) + " Examination", + title:exams[i].title, + id:exams[i]._id + }; + //console.log(minExamInfo); + minExamInfoArray.push(minExamInfo); + } + } + console.log(minExamInfoArray); + res.render('exams', {query: minExamInfoArray}); + }); }); /* Render/GET search (exam) page */ @@ -75,8 +113,6 @@ app.get('/exams.html', function (req,res) { });*/ - - function getExamsForCourseCode(courseCode) { dbFile.get_all_exams(courseCode, function (exams) { if (exams.length == 0){ @@ -88,4 +124,9 @@ function getExamsForCourseCode(courseCode) { }); } + module.exports = router; + +function toProperCase(string) { + return string.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); +}
\ No newline at end of file |
