refactor(groups): small groups-creation cleanup

This commit is contained in:
Tyler Renelle 2014-01-30 21:53:23 -07:00
parent 0aec4caa78
commit a960c63f00

View file

@ -147,16 +147,15 @@ api.create = function(req, res, next) {
group.balance = 1;
user.balance--;
user.save(function(err){
if(err) return res.json(500,{err:err});
group.save(function(err, saved){
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);
});
});
});
async.waterfall([
function(cb){user.save(cb)},
function(saved,ct,cb){group.save(cb)},
function(saved,ct,cb){saved.populate('members',nameFields,cb)}
],function(err,saved){
if (err) return next(err);
res.json(saved);
});
}else{
async.waterfall([
function(cb){