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,20 +285,7 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
}
pairedWith = pairedWith.pop();
index = pairedWith.uncompletedCoursewares.indexOf(coursewareHash);
if (index > -1) {
pairedWith.progressTimestamps.push(Date.now() || 0);
pairedWith.uncompletedCoursewares.splice(index, 1);
}
pairedWith.completedCoursewares.push({
_id: coursewareHash,
completedWith: req.user._id,
completedDate: isCompletedDate,
solution: solutionLink,
githubLink: githubLink
});
req.user.completedCoursewares.push({
_id: coursewareHash,
@ -312,6 +299,27 @@ exports.completedZiplineOrBasejump = function (req, res, next) {
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);
if (index > -1) {
pairedWith.progressTimestamps.push(Date.now() || 0);
pairedWith.uncompletedCoursewares.splice(index, 1);
}
pairedWith.completedCoursewares.push({
_id: coursewareHash,
completedWith: req.user._id,
completedDate: isCompletedDate,
solution: solutionLink,
githubLink: githubLink
});
pairedWith.save(function (err, paired) {
if (err) {
return next(err);