diff --git a/source/controller/dashboard.js b/source/controller/dashboard.js index e576a13..41ad039 100644 --- a/source/controller/dashboard.js +++ b/source/controller/dashboard.js @@ -54,21 +54,25 @@ var forceSyncIVLE = function (req, res, next) { } } -var findTutorials = function (req, res, next) { +// Query methods + +// Returns JSON object containing users tutorial sessions and roles +var getTutorials = function (req, res, next) { if (req.body.auth.success) { var user = req.body.auth.decoded; - var tuts = Tutorial.findTutorialSession(user.id).catch(function (err) { + console.log(user.id); + Tutorial.getTutorialsession(user.id).catch(function (err) { res.json({success: false, message: err}); - }).then(function() { - res.json({success: true, result: 'Synchronization Complete'}); + }).then(function (data) { + res.json({success: true, result: 'Found tutorials'}); + console.log(data[0].dataValues); }); - console.log(tuts); } else { res.send("Permission denied"); - } } + module.exports.get = get; module.exports.forceSyncIVLE = forceSyncIVLE; -module.exports.findTutorials = findTutorials; \ No newline at end of file +module.exports.getTutorials = getTutorials; \ No newline at end of file diff --git a/source/router.js b/source/router.js index 5013946..d5596a5 100644 --- a/source/router.js +++ b/source/router.js @@ -17,7 +17,8 @@ router.get ('/login/callback', login.callback); router.get ('/dashboard', auth.ensureAuth, dashboard.get); router.post('/api/dashboard/forceSyncIVLE', auth.ensureAuth, dashboard.forceSyncIVLE); -router.post('/api/dashboard/findTutorials', auth.ensureAuth, dashboard.findTutorials); +router.post('/api/dashboard/getTutorials', auth.ensureAuth, dashboard.getTutorials); + //router.post('/api/dashboard/forceSyncIVLE', auth.ensureAuth, dashboard.forceSyncIVLE); //router.post ('/api/dashboard/getAllUserTutorialSessions', auth.ensureAuth, dashboard.getAllUserTutorialSessions); diff --git a/source/view/dashboard.ejs b/source/view/dashboard.ejs index 5e8a6f7..7217d08 100644 --- a/source/view/dashboard.ejs +++ b/source/view/dashboard.ejs @@ -8,7 +8,7 @@ User is: <%= user.name %> - +
@@ -36,10 +36,10 @@ User is: <%= user.name %> }); } - function findTutorials() { + function getTutorials() { $.ajax({ type: 'POST', - url: '/api/dashboard/findTutorials', + url: '/api/dashboard/getTutorials', data: { }, dataType: 'json', success: function(data) { @@ -52,6 +52,10 @@ User is: <%= user.name %> syncIVLE(); }); + $('#get-mods').click(function() { + getTutorials(); + }); +