mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-14 21:27:23 +01:00
fix(challenges): leave chal from invalid group
This commit is contained in:
@@ -577,11 +577,13 @@ api.getChallenge = {
|
||||
const group = await Group.getGroup({
|
||||
user, groupId: challenge.group, fields: `${basicGroupFields} purchased`, optionalMembership: true,
|
||||
});
|
||||
if (!group || !challenge.canView(user, group)) throw new NotFound(res.t('challengeNotFound'));
|
||||
group.purchased = undefined;
|
||||
|
||||
if (!group && !challenge.canView(user, group)) throw new NotFound(res.t('challengeNotFound'));
|
||||
const chalRes = challenge.toJSON();
|
||||
chalRes.group = group.toJSON({ minimize: true });
|
||||
if (group) {
|
||||
group.purchased = undefined;
|
||||
chalRes.group = group.toJSON({ minimize: true });
|
||||
}
|
||||
|
||||
// Instead of populate we make a find call manually because of https://github.com/Automattic/mongoose/issues/3833
|
||||
const chalLeader = await User.findById(chalRes.leader).select(nameFields).exec();
|
||||
chalRes.leader = chalLeader ? chalLeader.toJSON({ minimize: true }) : null;
|
||||
|
||||
Reference in New Issue
Block a user