Skip to content

Commit 9dcb15b

Browse files
Merge pull request #64 from narekcat/issue-60
Fix issue 60
2 parents 3bb1f37 + 78fe6f3 commit 9dcb15b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/services/ChallengeService.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async function searchChallenges (currentUser, criteria) {
9999
if (criteria.tag) {
100100
boolQuery.push({ match_phrase: { tags: criteria.tag } })
101101
}
102-
if (criteria.group) {
102+
if (criteria.group && !_.isUndefined(currentUser)) {
103103
boolQuery.push({ match_phrase: { groups: criteria.group } })
104104
}
105105
if (criteria.gitRepoURL) {
@@ -138,12 +138,18 @@ async function searchChallenges (currentUser, criteria) {
138138

139139
const mustQuery = []
140140

141+
let mustNotQuery
142+
141143
const accessQuery = []
142144

143145
if (!_.isUndefined(currentUser) && currentUser.handle) {
144146
accessQuery.push({ match_phrase: { createdBy: currentUser.handle } })
145147
}
146148

149+
if (_.isUndefined(currentUser)) {
150+
mustNotQuery = { exists: { field: 'groups' } }
151+
}
152+
147153
if (criteria.memberId) {
148154
const ids = await helper.listChallengesByMember(criteria.memberId)
149155
accessQuery.push({ terms: { _id: ids } })
@@ -171,9 +177,10 @@ async function searchChallenges (currentUser, criteria) {
171177
size: criteria.perPage,
172178
from: (criteria.page - 1) * criteria.perPage, // Es Index starts from 0
173179
body: {
174-
query: mustQuery.length > 0 ? {
180+
query: mustQuery.length > 0 || !_.isUndefined(mustNotQuery) ? {
175181
bool: {
176-
must: mustQuery
182+
must: mustQuery,
183+
must_not: mustNotQuery
177184
}
178185
} : {
179186
match_all: {}

0 commit comments

Comments
 (0)