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 @@ -82,7 +82,7 @@ async function searchChallenges (currentUser, criteria) {
82
82
if ( criteria . tag ) {
83
83
boolQuery . push ( { match_phrase : { tags : criteria . tag } } )
84
84
}
85
- if ( criteria . group ) {
85
+ if ( criteria . group && ! _ . isUndefined ( currentUser ) ) {
86
86
boolQuery . push ( { match_phrase : { groups : criteria . group } } )
87
87
}
88
88
if ( criteria . gitRepoURL ) {
@@ -121,12 +121,18 @@ async function searchChallenges (currentUser, criteria) {
121
121
122
122
const mustQuery = [ ]
123
123
124
+ let mustNotQuery
125
+
124
126
const accessQuery = [ ]
125
127
126
128
if ( ! _ . isUndefined ( currentUser ) && currentUser . handle ) {
127
129
accessQuery . push ( { match_phrase : { createdBy : currentUser . handle } } )
128
130
}
129
131
132
+ if ( _ . isUndefined ( currentUser ) ) {
133
+ mustNotQuery = { exists : { field : 'groups' } }
134
+ }
135
+
130
136
if ( criteria . memberId ) {
131
137
const ids = await helper . listChallengesByMember ( criteria . memberId )
132
138
accessQuery . push ( { terms : { _id : ids } } )
@@ -154,9 +160,10 @@ async function searchChallenges (currentUser, criteria) {
154
160
size : criteria . perPage ,
155
161
from : ( criteria . page - 1 ) * criteria . perPage , // Es Index starts from 0
156
162
body : {
157
- query : mustQuery . length > 0 ? {
163
+ query : mustQuery . length > 0 || ! _ . isUndefined ( mustNotQuery ) ? {
158
164
bool : {
159
- must : mustQuery
165
+ must : mustQuery ,
166
+ must_not : mustNotQuery
160
167
}
161
168
} : {
162
169
match_all : { }
You can’t perform that action at this time.
0 commit comments