[#1828] don't let users create party if they already belong to one

This commit is contained in:
Tyler Renelle 2013-11-15 18:16:48 -08:00
parent 2b286ba889
commit 53db31d4fb

View file

@ -177,13 +177,21 @@ api.create = function(req, res, next) {
});
});
}else{
group.save(function(err, saved){
async.waterfall([
function(cb){
Group.findOne({type:'party',members:{$in:[user._id]}},cb);
},
function(found, cb){
if (found) return cb('Already in a party, try refreshing.');
group.save(cb);
},
function(saved, count, cb){
saved.populate('members', nameFields, cb);
}
], function(err, populated){
if (err) return res.json(500,{err:err});
saved.populate('members', nameFields, function(err, populated){
if (err) return res.json(500,{err:err});
return res.json(populated);
});
});
return res.json(populated);
})
}
}