diff --git a/app.js b/app.js index 5f57bf1a4e..947edb57cf 100644 --- a/app.js +++ b/app.js @@ -168,24 +168,19 @@ app.get('/account/unlink/:provider', userController.getOauthUnlink); */ app.post('/completed_challenge', function(req, res) { console.log(req.user); - - User.findById(req.user.id, function (err, user) { - if (err) { - console.log(err); - res.status(500); - return res.send('something went wrong'); - } - user.challengesHash[parseInt(req.body.cn)] = Math.round(+new Date()/1000); - user.save(function(err, newDats) { - if (err) { - console.log(err); - res.status(500); - return res.send('something went wrong'); - } - console.log('Suer', user); - res.status(200).send('saved'); - }); - }); + req.user.challengesHash[parseInt(req.body.cn)] = Math.round(+new Date() / 1000); + req.user.challengesCompleted = function() { + var completed = []; + for (i = 0; i < h.length; i++) { + if (h[i] > 0) { + completed.push(i); + } + return completed; + } + } + req.user.save(); + console.log(req.user.challengesHash); + console.log(req.user.challengesCompleted); }); /** diff --git a/controllers/home.js b/controllers/home.js index f1bab63f94..b29d5ac698 100644 --- a/controllers/home.js +++ b/controllers/home.js @@ -6,7 +6,8 @@ exports.index = function(req, res) { if (req.user) { if (req.user.challengesCompleted.length > 0) { - nextChallenge = Math.max.apply(Math, req.user.challengesCompleted) + 1; + Object.values(req.user.challengesHash); + nextChallenge = Math.max.apply(Math, req.user.challengesHash) + 1; res.redirect("challenges/" + nextChallenge); } else { res.redirect("challenges/0"); diff --git a/views/partials/navbar.jade b/views/partials/navbar.jade index 4170e392c6..486ad6d731 100644 --- a/views/partials/navbar.jade +++ b/views/partials/navbar.jade @@ -20,8 +20,8 @@ img(src='#{user.profile.picture}') else img(src='#{user.gravatar(60)}') - | #{user.profile.name || user.email || user.id} [ #{Object.keys(user.challengesHash).length} ]  - i.caret + | #{user.profile.name || user.email || user.id} [ #{user.completedChallengeCount)} ]  + i.caret ul.dropdown-menu li a(href='/')