diff options
| author | Waref Haque <warefhaque@Warefs-MacBook-Pro.local> | 2016-07-19 04:21:17 +0000 |
|---|---|---|
| committer | Waref Haque <warefhaque@Warefs-MacBook-Pro.local> | 2016-07-19 04:21:17 +0000 |
| commit | daefddd8dc45e7044e83bd40706cfdca36471fe9 (patch) | |
| tree | 6d3617d1385d7e81af353f8196ddbd67204e26b2 /routes/index.js | |
| parent | 5392cf6f6fa08d666ee58a2a57757192d9a50398 (diff) | |
proper exams rendering
Diffstat (limited to 'routes/index.js')
| -rw-r--r-- | routes/index.js | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/routes/index.js b/routes/index.js index 457fbd1..1406143 100644 --- a/routes/index.js +++ b/routes/index.js @@ -28,9 +28,46 @@ 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 + }; + //console.log(minExamInfo); + minExamInfoArray.push(minExamInfo); + } + } + console.log(minExamInfoArray); + res.render('exams', {query: minExamInfoArray}); + }); }); /* Render/GET search (exam) page */ @@ -67,3 +104,7 @@ 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 |
