File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ async function searchChallenges (currentUser, criteria) {
99
99
if ( criteria . tag ) {
100
100
boolQuery . push ( { match_phrase : { tags : criteria . tag } } )
101
101
}
102
- if ( criteria . group ) {
102
+ if ( criteria . group && ! _ . isUndefined ( currentUser ) ) {
103
103
boolQuery . push ( { match_phrase : { groups : criteria . group } } )
104
104
}
105
105
if ( criteria . gitRepoURL ) {
@@ -138,12 +138,18 @@ async function searchChallenges (currentUser, criteria) {
138
138
139
139
const mustQuery = [ ]
140
140
141
+ let mustNotQuery
142
+
141
143
const accessQuery = [ ]
142
144
143
145
if ( ! _ . isUndefined ( currentUser ) && currentUser . handle ) {
144
146
accessQuery . push ( { match_phrase : { createdBy : currentUser . handle } } )
145
147
}
146
148
149
+ if ( _ . isUndefined ( currentUser ) ) {
150
+ mustNotQuery = { exists : { field : 'groups' } }
151
+ }
152
+
147
153
if ( criteria . memberId ) {
148
154
const ids = await helper . listChallengesByMember ( criteria . memberId )
149
155
accessQuery . push ( { terms : { _id : ids } } )
@@ -171,9 +177,10 @@ async function searchChallenges (currentUser, criteria) {
171
177
size : criteria . perPage ,
172
178
from : ( criteria . page - 1 ) * criteria . perPage , // Es Index starts from 0
173
179
body : {
174
- query : mustQuery . length > 0 ? {
180
+ query : mustQuery . length > 0 || ! _ . isUndefined ( mustNotQuery ) ? {
175
181
bool : {
176
- must : mustQuery
182
+ must : mustQuery ,
183
+ must_not : mustNotQuery
177
184
}
178
185
} : {
179
186
match_all : { }
You can’t perform that action at this time.
0 commit comments