Change completion event to remove duplicate entries if the user states they paired with themselves

This commit is contained in:
Nathan Leniz
2015-03-29 21:15:18 +09:00
parent 1fc3cffdbf
commit aa2f0e8af8
2 changed files with 22 additions and 14 deletions

View File

@ -285,6 +285,27 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
} }
pairedWith = pairedWith.pop(); pairedWith = pairedWith.pop();
req.user.completedCoursewares.push({
_id: coursewareHash,
completedWith: pairedWith._id,
completedDate: isCompletedDate,
solution: solutionLink,
githubLink: githubLink
});
req.user.save(function (err, user) {
if (err) {
return next(err);
}
debug('this is the user object returned %s,' +
' this is the req.user._id %s, ' +
'this is the pairedWith._id %s', user, req.user._id, pairedWith._id);
debug(req.user._id.toString() === pairedWith._id.toString());
if (req.user._id.toString() === pairedWith._id.toString()) {
return res.sendStatus(200);
}
index = pairedWith.uncompletedCoursewares.indexOf(coursewareHash); index = pairedWith.uncompletedCoursewares.indexOf(coursewareHash);
if (index > -1) { if (index > -1) {
pairedWith.progressTimestamps.push(Date.now() || 0); pairedWith.progressTimestamps.push(Date.now() || 0);
@ -299,19 +320,6 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
solution: solutionLink, solution: solutionLink,
githubLink: githubLink githubLink: githubLink
}); });
req.user.completedCoursewares.push({
_id: coursewareHash,
completedWith: pairedWith._id,
completedDate: isCompletedDate,
solution: solutionLink,
githubLink: githubLink
});
req.user.save(function (err, user) {
if (err) {
return next(err);
}
pairedWith.save(function (err, paired) { pairedWith.save(function (err, paired) {
if (err) { if (err) {
return next(err); return next(err);

View File

@ -164,7 +164,7 @@ $(document).ready(function() {
coursewareHash: passedCoursewareHash, coursewareHash: passedCoursewareHash,
coursewareName: passedCoursewareName, coursewareName: passedCoursewareName,
completedWith: didCompleteWith, completedWith: didCompleteWith,
publicURL: publicURl, publicURL: publicURL,
githubURL: githubURL, githubURL: githubURL,
challengeType: challengeType challengeType: challengeType
} }