coursewares properly push timestamps to user object

This commit is contained in:
Nathan Leniz
2015-03-21 14:28:00 +09:00
parent cd89ad1574
commit be91849d20
4 changed files with 27 additions and 34 deletions

14
app.js
View File

@ -447,19 +447,7 @@ app.get('/sitemap.xml', resourcesController.sitemap);
* 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.

View File

@ -216,16 +216,18 @@ exports.completedCourseware = function (req, res) {
var isCompletedDate = Math.round(+new Date() / 1000);
var coursewareHash = req.body.coursewareInfo.coursewareHash;
debug('this is the coursewarehash we got', coursewareHash);
req.user.completedCoursewares.push({
_id: coursewareHash,
completedDate: isCompletedDate
});
var index = req.user.uncompletedCoursewares.indexOf(coursewareHash);
if (index > -1) {
var index = req.user.completedCoursewares.indexOf(coursewareHash);
debug('this is the index of the found courseware', index);
if (index === -1) {
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) {
@ -233,7 +235,7 @@ exports.completedCourseware = function (req, res) {
throw err;
}
if (user) {
res.send(true)
res.send(true);
}
});
};

View File

@ -30,19 +30,19 @@ $(document).ready(function() {
.addClass('animated fadeInDown');
});
$('.completed-challenge').on('click', function() {
$('#complete-challenge-dialog').modal('show');
// Only post to server if there is an authenticated user
if ($('.signup-btn-nav').length < 1) {
l = location.pathname.split('/');
cn = l[l.length - 1];
$.ajax({
type: 'POST',
data: {challengeNumber: cn},
url: '/completed-challenge/'
});
}
});
//$('.completed-challenge').on('click', function() {
// $('#complete-challenge-dialog').modal('show');
// // Only post to server if there is an authenticated user
// if ($('.signup-btn-nav').length < 1) {
// l = location.pathname.split('/');
// cn = l[l.length - 1];
// $.ajax({
// type: 'POST',
// data: {challengeNumber: cn},
// url: '/completed-challenge/'
// });
// }
//});
function completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash) {
@ -105,18 +105,21 @@ $(document).ready(function() {
editor.focus();
});
$('#next-courseware-button').on('click', function() {
console.log(passedCoursewareHash);
if ($('.signup-btn-nav').length < 1) {
$.post(
'/completed-courseware',
'/completed-courseware/',
{
coursewareInfo: {
coursewareHash: passedCoursewareHash
}
}).success(
function() {
function(res) {
if (res) {
window.location.href = '/coursewares';
}
}
)
);
}
});

View File

@ -30,7 +30,7 @@ block content
.modal-dialog.animated.zoomIn.fast-animation
.modal-content
.modal-header.challenge-list-header= compliment
a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
a.close.closing-x(href='#', data-dismiss='modal', aria-hidden='true') ×
.modal-body(ng-controller="pairedWithController")
.text-center
.animated.zoomInDown.delay-half