Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yeojoey committed Mar 15, 2017
1 parent 820e9a9 commit de39375
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
18 changes: 11 additions & 7 deletions source/controller/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
module.exports.getTutorials = getTutorials;
3 changes: 2 additions & 1 deletion source/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions source/view/dashboard.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body>
User is: <%= user.name %>

<br>


<button id="sync-ivle">sync</button>
Expand Down Expand Up @@ -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) {
Expand All @@ -52,6 +52,10 @@ User is: <%= user.name %>
syncIVLE();
});
$('#get-mods').click(function() {
getTutorials();
});
</script>


Expand Down

0 comments on commit de39375

Please sign in to comment.