coursewares properly push timestamps to user object
This commit is contained in:
14
app.js
14
app.js
@ -447,19 +447,7 @@ app.get('/sitemap.xml', resourcesController.sitemap);
|
|||||||
* and updates user.challengesHash & user.challengesCompleted
|
* and updates user.challengesHash & user.challengesCompleted
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
app.post('/completed-challenge', function (req, res) {
|
|
||||||
req.user.challengesHash[parseInt(req.body.challengeNumber)] =
|
|
||||||
Math.round(+new Date() / 1000);
|
|
||||||
var timestamp = req.user.challengesHash;
|
|
||||||
var points = 0;
|
|
||||||
for (var key in timestamp) {
|
|
||||||
if (timestamp[key] > 0 && req.body.challengeNumber < 54) {
|
|
||||||
points += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
req.user.points = points;
|
|
||||||
req.user.save();
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth sign-in routes.
|
* OAuth sign-in routes.
|
||||||
|
@ -216,16 +216,18 @@ exports.completedCourseware = function (req, res) {
|
|||||||
|
|
||||||
var isCompletedDate = Math.round(+new Date() / 1000);
|
var isCompletedDate = Math.round(+new Date() / 1000);
|
||||||
var coursewareHash = req.body.coursewareInfo.coursewareHash;
|
var coursewareHash = req.body.coursewareInfo.coursewareHash;
|
||||||
|
debug('this is the coursewarehash we got', coursewareHash);
|
||||||
|
|
||||||
req.user.completedCoursewares.push({
|
req.user.completedCoursewares.push({
|
||||||
_id: coursewareHash,
|
_id: coursewareHash,
|
||||||
completedDate: isCompletedDate
|
completedDate: isCompletedDate
|
||||||
});
|
});
|
||||||
|
|
||||||
var index = req.user.uncompletedCoursewares.indexOf(coursewareHash);
|
var index = req.user.completedCoursewares.indexOf(coursewareHash);
|
||||||
if (index > -1) {
|
debug('this is the index of the found courseware', index);
|
||||||
|
if (index === -1) {
|
||||||
req.user.progressTimestamps.push(Date.now() / 1000 | 0);
|
req.user.progressTimestamps.push(Date.now() / 1000 | 0);
|
||||||
req.user.uncompletedCoursewares.splice(index, 1)
|
req.user.uncompletedCoursewares.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
req.user.save(function (err, user) {
|
req.user.save(function (err, user) {
|
||||||
@ -233,7 +235,7 @@ exports.completedCourseware = function (req, res) {
|
|||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
if (user) {
|
if (user) {
|
||||||
res.send(true)
|
res.send(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
@ -30,19 +30,19 @@ $(document).ready(function() {
|
|||||||
.addClass('animated fadeInDown');
|
.addClass('animated fadeInDown');
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.completed-challenge').on('click', function() {
|
//$('.completed-challenge').on('click', function() {
|
||||||
$('#complete-challenge-dialog').modal('show');
|
// $('#complete-challenge-dialog').modal('show');
|
||||||
// Only post to server if there is an authenticated user
|
// // Only post to server if there is an authenticated user
|
||||||
if ($('.signup-btn-nav').length < 1) {
|
// if ($('.signup-btn-nav').length < 1) {
|
||||||
l = location.pathname.split('/');
|
// l = location.pathname.split('/');
|
||||||
cn = l[l.length - 1];
|
// cn = l[l.length - 1];
|
||||||
$.ajax({
|
// $.ajax({
|
||||||
type: 'POST',
|
// type: 'POST',
|
||||||
data: {challengeNumber: cn},
|
// data: {challengeNumber: cn},
|
||||||
url: '/completed-challenge/'
|
// url: '/completed-challenge/'
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
});
|
//});
|
||||||
|
|
||||||
|
|
||||||
function completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash) {
|
function completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash) {
|
||||||
@ -105,18 +105,21 @@ $(document).ready(function() {
|
|||||||
editor.focus();
|
editor.focus();
|
||||||
});
|
});
|
||||||
$('#next-courseware-button').on('click', function() {
|
$('#next-courseware-button').on('click', function() {
|
||||||
|
console.log(passedCoursewareHash);
|
||||||
if ($('.signup-btn-nav').length < 1) {
|
if ($('.signup-btn-nav').length < 1) {
|
||||||
$.post(
|
$.post(
|
||||||
'/completed-courseware',
|
'/completed-courseware/',
|
||||||
{
|
{
|
||||||
coursewareInfo: {
|
coursewareInfo: {
|
||||||
coursewareHash: passedCoursewareHash
|
coursewareHash: passedCoursewareHash
|
||||||
}
|
}
|
||||||
}).success(
|
}).success(
|
||||||
function() {
|
function(res) {
|
||||||
|
if (res) {
|
||||||
window.location.href = '/coursewares';
|
window.location.href = '/coursewares';
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user