reached a stopping point, trying to fix a production bug
This commit is contained in:
31
app.js
31
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);
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -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");
|
||||
|
@ -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='/')
|
||||
|
Reference in New Issue
Block a user