Update to bonfires. Successfully completing triggers a save. "Paired with" form field moved to bonfire view. Controller hardened for checking pair as button is no longer disabled for unfound username
This commit is contained in:
@@ -324,44 +324,62 @@ exports.completedBonfire = function (req, res, next) {
|
||||
req.user.uncompletedChallenges.splice(index, 1);
|
||||
}
|
||||
pairedWith = pairedWith.pop();
|
||||
if (pairedWith) {
|
||||
|
||||
index = pairedWith.uncompletedChallenges.indexOf(challengeId);
|
||||
if (index > -1) {
|
||||
pairedWith.progressTimestamps.push(Date.now() || 0);
|
||||
pairedWith.uncompletedChallenges.splice(index, 1);
|
||||
index = pairedWith.uncompletedChallenges.indexOf(challengeId);
|
||||
if (index > -1) {
|
||||
pairedWith.progressTimestamps.push(Date.now() || 0);
|
||||
pairedWith.uncompletedChallenges.splice(index, 1);
|
||||
|
||||
}
|
||||
|
||||
pairedWith.completedChallenges.push({
|
||||
_id: challengeId,
|
||||
name: challengeName,
|
||||
completedWith: req.user._id,
|
||||
completedDate: isCompletedDate,
|
||||
solution: isSolution,
|
||||
challengeType: 5
|
||||
});
|
||||
|
||||
req.user.completedChallenges.push({
|
||||
_id: challengeId,
|
||||
name: challengeName,
|
||||
completedWith: pairedWith._id,
|
||||
completedDate: isCompletedDate,
|
||||
solution: isSolution,
|
||||
challengeType: 5
|
||||
});
|
||||
}
|
||||
// User said they paired, but pair wasn't found
|
||||
req.user.completedChallenges.push({
|
||||
_id: challengeId,
|
||||
name: challengeName,
|
||||
completedWith: null,
|
||||
completedDate: isCompletedDate,
|
||||
solution: isSolution,
|
||||
challengeType: 5
|
||||
});
|
||||
|
||||
pairedWith.completedChallenges.push({
|
||||
_id: challengeId,
|
||||
name: challengeName,
|
||||
completedWith: req.user._id,
|
||||
completedDate: isCompletedDate,
|
||||
solution: isSolution,
|
||||
challengeType: 5
|
||||
});
|
||||
|
||||
req.user.completedChallenges.push({
|
||||
_id: challengeId,
|
||||
name: challengeName,
|
||||
completedWith: pairedWith._id,
|
||||
completedDate: isCompletedDate,
|
||||
solution: isSolution,
|
||||
challengeType: 5
|
||||
});
|
||||
|
||||
req.user.save(function (err, user) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
pairedWith.save(function (err, paired) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (user && paired) {
|
||||
if (pairedWith) {
|
||||
pairedWith.save(function (err, paired) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
if (user && paired) {
|
||||
res.send(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (user) {
|
||||
res.send(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user