fix: remove guild or party when user looks it up if it does not exist

closes #7878
fixes #7724
This commit is contained in:
Husman
2016-08-06 17:28:07 -07:00
committed by Blade Barringer
parent ae533652c3
commit bba56b8c29
5 changed files with 101 additions and 6 deletions

View File

@@ -159,6 +159,17 @@ schema.statics.getGroup = async function getGroup (options = {}) {
if (fields) mQuery.select(fields);
if (populateLeader === true) mQuery.populate('leader', nameFields);
let group = await mQuery.exec();
if (!group) {
if (groupId === user.party._id) {
// reset party object to default state
user.party = {};
} else {
removeFromArray(user.guilds, groupId);
}
await user.save();
}
return group;
};