made parallel 'points' infrastructure

This commit is contained in:
Michael Q Larson
2014-12-05 20:44:42 -08:00
parent 07ba7e4fcb
commit 177dc900cf
7 changed files with 110 additions and 267 deletions

21
app.js
View File

@@ -163,21 +163,18 @@ app.get('/account/unlink/:provider', userController.getOauthUnlink);
/**
* API examples routes.
* accepts a post request. the challenge id req.body.challengeNumber
* and updates user.challengesHash & user.challengesCompleted
*
*/
app.post('/completed_challenge', function(req, res) {
req.user.challengesHash[parseInt(req.body.cn)] = Math.round(+new Date() / 1000);
req.user.challengesCompleted = function() {
var completed = [];
var h = req.user.challengesHash;
for (i = 0; i < h.length; i++) {
console.log(h[i] > 0)
if (h[i] > 0) {
console.log(h[i]);
completed.push(i);
}
return completed;
}
req.user.challengesHash[parseInt(req.body.challengeNumber)] = Math.round(+new Date() / 1000);
var ch = req.user.challengesHash;
var p = 0;
for (k in ch) {
if (ch[k] > 0) { p += 1}
}
req.user.points = p;
req.user.save();
});