Resolving issue with saving to "paired with" user profile

This commit is contained in:
Nathan Leniz
2015-01-27 22:25:48 -05:00
parent 3844542651
commit 5294462e4c
2 changed files with 10 additions and 3 deletions

6
app.js
View File

@ -288,6 +288,8 @@ app.post('/completed-bonfire/', function (req, res) {
var isCompletedDate = Math.round(+new Date() / 1000); var isCompletedDate = Math.round(+new Date() / 1000);
var bonfireHash = req.body.bonfireInfo.bonfireHash; var bonfireHash = req.body.bonfireInfo.bonfireHash;
var isSolution = req.body.bonfireInfo.solution; var isSolution = req.body.bonfireInfo.solution;
// TODO
debug(isCompletedWith, 'Is completed with');
if (isCompletedWith) { if (isCompletedWith) {
var paired = User.find({"profile.username": isCompletedWith}).limit(1); var paired = User.find({"profile.username": isCompletedWith}).limit(1);
@ -300,13 +302,15 @@ app.post('/completed-bonfire/', function (req, res) {
if (index > -1) { if (index > -1) {
req.user.uncompletedBonfires.splice(index,1) req.user.uncompletedBonfires.splice(index,1)
} }
pairedWith = pairedWith.pop();
//debug('This is paired with', Object.keys(pairedWith));
debug('This is paired with\'s uncompleted bonfires array', pairedWith.uncompletedBonfires);
index = pairedWith.uncompletedBonfires.indexOf(bonfireHash); index = pairedWith.uncompletedBonfires.indexOf(bonfireHash);
if (index > -1) { if (index > -1) {
pairedWith.uncompletedBonfires.splice(index,1) pairedWith.uncompletedBonfires.splice(index,1)
} }
pairedWith = pairedWith.pop();
pairedWith.completedBonfires.push({ pairedWith.completedBonfires.push({
_id: bonfireHash, _id: bonfireHash,
completedWith: req.user._id, completedWith: req.user._id,

View File

@ -33,9 +33,12 @@ exports.index = function(req, res) {
}; };
exports.returnNextBonfire = function(req, res, next) { exports.returnNextBonfire = function(req, res, next) {
// TODO
//var tempUser = false;
if (!req.user) { if (!req.user) {
req.user = new User(); res.redirect('bonfires/meet-bonfire');
//tempUser = true;
//req.user = new User();
} }
var currentTime = parseInt(+new Date() / 1000) var currentTime = parseInt(+new Date() / 1000)
if (currentTime - req.user.lastContentSync > 86400) { if (currentTime - req.user.lastContentSync > 86400) {