mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-13 17:52:22 +00:00
fix(challenges): leave chal from invalid group
This commit is contained in:
parent
a6792a4f08
commit
8f64afe9df
1 changed files with 6 additions and 4 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue