mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-13 17:52:22 +00:00
fix(challenges): map IDs
This commit is contained in:
parent
013f8bcca7
commit
d4e3e83d46
1 changed files with 13 additions and 6 deletions
|
|
@ -397,20 +397,27 @@ api.getUserChallenges = {
|
||||||
const { page } = req.query;
|
const { page } = req.query;
|
||||||
|
|
||||||
const { user } = res.locals;
|
const { user } = res.locals;
|
||||||
const orOptions = [
|
|
||||||
{ _id: { $in: user.challenges } }, // Challenges where the user is participating
|
|
||||||
];
|
|
||||||
|
|
||||||
orOptions.push({ leader: user._id });
|
// Challenges the user owns
|
||||||
|
const orOptions = [{ leader: user._id }];
|
||||||
|
|
||||||
|
// Challenges where the user is participating
|
||||||
|
if (user.challenges.length > 0) {
|
||||||
|
orOptions.push({ _id: { $in: user.challenges } });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Challenges in groups user is a member of, plus public challenges
|
||||||
if (!req.query.member) {
|
if (!req.query.member) {
|
||||||
const userGroups = await Group.getGroups({
|
const userGroups = await Group.getGroups({
|
||||||
user,
|
user,
|
||||||
types: ['party', 'guilds', 'tavern'],
|
types: ['party', 'guilds', 'tavern'],
|
||||||
});
|
});
|
||||||
|
const userGroupIds = userGroups.map((userGroup) => {
|
||||||
|
return userGroup._id;
|
||||||
|
});
|
||||||
orOptions.push({
|
orOptions.push({
|
||||||
group: { $in: userGroups },
|
group: { $in: userGroupIds },
|
||||||
}); // Challenges in groups where I'm a member
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue