writes completed challenges to database
This commit is contained in:
26
app.js
26
app.js
@ -33,6 +33,10 @@ var userController = require('./controllers/user');
|
|||||||
var apiController = require('./controllers/api');
|
var apiController = require('./controllers/api');
|
||||||
var contactController = require('./controllers/contact');
|
var contactController = require('./controllers/contact');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User model
|
||||||
|
*/
|
||||||
|
var User = require('./models/User');
|
||||||
/**
|
/**
|
||||||
* API keys and Passport configuration.
|
* API keys and Passport configuration.
|
||||||
*/
|
*/
|
||||||
@ -163,9 +167,25 @@ app.get('/account/unlink/:provider', userController.getOauthUnlink);
|
|||||||
* API examples routes.
|
* API examples routes.
|
||||||
*/
|
*/
|
||||||
app.post('/completed_challenge', function(req, res) {
|
app.post('/completed_challenge', function(req, res) {
|
||||||
req.user.challengesHash[req.body.cn] = Math.round(+new Date()/1000);
|
console.log(req.user);
|
||||||
req.user.save();
|
|
||||||
console.log(req.user.challengesHash);
|
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');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,7 +14,7 @@ var userSchema = new mongoose.Schema({
|
|||||||
instagram: String,
|
instagram: String,
|
||||||
tokens: Array,
|
tokens: Array,
|
||||||
challengesCompleted: { type: Array, default: [] },
|
challengesCompleted: { type: Array, default: [] },
|
||||||
challengesHash: { type: {}, default: { '-1': 'void'} },
|
challengesHash: {},
|
||||||
|
|
||||||
profile: {
|
profile: {
|
||||||
name: { type: String, default: '' },
|
name: { type: String, default: '' },
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
.panel-body
|
.panel-body
|
||||||
ol(start='0')
|
ol(start='0')
|
||||||
li
|
li
|
||||||
a(href="/challenges/0", class="#{ cc.hasOwnProperty('0') ? 'strikethrough' : '' }") A One-minute Introduction to Free Code Camp
|
//a(href="/challenges/0", class="#{ cc.hasOwnProperty('0') ? 'strikethrough' : '' }") A One-minute Introduction to Free Code Camp
|
||||||
| (1 min)
|
//| (1 min)
|
||||||
//li
|
//li
|
||||||
// a(href="/challenges/1", class="#{ cc.indexOf(1) > -1 ? 'strikethrough' : '' }") Enter the Free Code Camp Chat Room
|
// a(href="/challenges/1", class="#{ cc.indexOf(1) > -1 ? 'strikethrough' : '' }") Enter the Free Code Camp Chat Room
|
||||||
// | (5 mins)
|
// | (5 mins)
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
img(src='#{user.profile.picture}')
|
img(src='#{user.profile.picture}')
|
||||||
else
|
else
|
||||||
img(src='#{user.gravatar(60)}')
|
img(src='#{user.gravatar(60)}')
|
||||||
| #{user.profile.name || user.email || user.id} [ #{Object.keys(user.challengesHash).length} ]
|
//| #{user.profile.name || user.email || user.id} [ #{Object.keys(user.challengesHash).length} ]
|
||||||
i.caret
|
i.caret
|
||||||
ul.dropdown-menu
|
ul.dropdown-menu
|
||||||
li
|
li
|
||||||
|
Reference in New Issue
Block a user