mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Removed redundant code when removing group invitations
This commit is contained in:
@@ -87,36 +87,23 @@ GroupSchema.pre('save', function(next){
|
||||
|
||||
GroupSchema.pre('remove', function(next) {
|
||||
var group = this;
|
||||
if ( group.type == "guild" ) {
|
||||
async.waterfall([
|
||||
function(cb) {
|
||||
User.find({
|
||||
'invitations.guilds.id': group._id
|
||||
}, cb);
|
||||
var invitationQuery = {};
|
||||
var groupType = group.type;
|
||||
//Add an 's' to group type guild because the model has the plural version
|
||||
if (group.type == "guild") groupType += "s";
|
||||
invitationQuery['invitations.' + groupType + '.id'] = group._id;
|
||||
User.find(invitationQuery, cb);
|
||||
},
|
||||
function(users, cb) {
|
||||
if (users) {
|
||||
users.forEach(function (user, index, array) {
|
||||
if ( group.type == "party" ) {
|
||||
user.invitations.party = {};
|
||||
} else {
|
||||
var i = _.findIndex(user.invitations.guilds, {id: group._id});
|
||||
user.invitations.guilds.splice(i, 1);
|
||||
user.save();
|
||||
});
|
||||
}
|
||||
cb();
|
||||
}
|
||||
], next);
|
||||
} else if ( group.type == "party" ) {
|
||||
async.waterfall([
|
||||
function(cb) {
|
||||
User.find({
|
||||
'invitations.party.id': group._id
|
||||
}, cb);
|
||||
},
|
||||
function(users, cb) {
|
||||
if (users) {
|
||||
users.forEach(function (user, index, array) {
|
||||
if (user.invitations.party.id === group._id) {
|
||||
user.invitations.party = {};
|
||||
}
|
||||
user.save();
|
||||
});
|
||||
@@ -124,9 +111,6 @@ GroupSchema.pre('remove', function(next) {
|
||||
cb();
|
||||
}
|
||||
], next);
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
GroupSchema.post('remove', function(group) {
|
||||
|
||||
Reference in New Issue
Block a user