Filter challenge by owned (#12527)

* when filtering by owned challenges, challenges that a user owns but has not joined will be included

* add tests for filtering challenges by owned

* fix lint
This commit is contained in:
Kirsty
2020-09-07 14:30:01 +01:00
committed by GitHub
parent e5ccb634e0
commit d37c156fa0
2 changed files with 169 additions and 199 deletions

View File

@@ -371,10 +371,7 @@ api.getUserChallenges = {
{ _id: { $in: user.challenges } }, // Challenges where the user is participating
];
const { owned } = req.query;
if (!owned) {
orOptions.push({ leader: user._id });
}
orOptions.push({ leader: user._id });
if (!req.query.member) {
orOptions.push({
@@ -386,6 +383,7 @@ api.getUserChallenges = {
$and: [{ $or: orOptions }],
};
const { owned } = req.query;
if (owned) {
if (owned === 'not_owned') {
query.$and.push({ leader: { $ne: user._id } });