@@ -342,6 +342,29 @@ async function searchChallenges (currentUser, criteria) {
342
342
}
343
343
}
344
344
345
+ const accessQuery = [ ]
346
+ let memberChallengeIds
347
+
348
+ // FIXME: This is wrong!
349
+ // if (!_.isUndefined(currentUser) && currentUser.handle) {
350
+ // accessQuery.push({ match_phrase: { createdBy: currentUser.handle } })
351
+ // }
352
+
353
+ if ( criteria . memberId ) {
354
+ // logger.error(`memberId ${criteria.memberId}`)
355
+ memberChallengeIds = await helper . listChallengesByMember ( criteria . memberId )
356
+ // logger.error(`response ${JSON.stringify(ids)}`)
357
+ accessQuery . push ( { terms : { _id : memberChallengeIds } } )
358
+ }
359
+
360
+ if ( accessQuery . length > 0 ) {
361
+ mustQuery . push ( {
362
+ bool : {
363
+ should : accessQuery
364
+ }
365
+ } )
366
+ }
367
+
345
368
// FIXME: Tech Debt
346
369
let excludeTasks = true
347
370
// if you're an admin or m2m, security rules wont be applied
@@ -372,6 +395,7 @@ async function searchChallenges (currentUser, criteria) {
372
395
mustQuery . push ( {
373
396
bool : {
374
397
should : [
398
+ ...( _ . get ( memberChallengeIds , 'length' , 0 ) > 0 ? { terms : { _id : memberChallengeIds } } : { } ) ,
375
399
{ bool : { must_not : { exists : { field : 'task.isTask' } } } } ,
376
400
{ match_phrase : { 'task.isTask' : false } } ,
377
401
{
@@ -400,28 +424,6 @@ async function searchChallenges (currentUser, criteria) {
400
424
} )
401
425
}
402
426
403
- const accessQuery = [ ]
404
-
405
- // FIXME: This is wrong!
406
- // if (!_.isUndefined(currentUser) && currentUser.handle) {
407
- // accessQuery.push({ match_phrase: { createdBy: currentUser.handle } })
408
- // }
409
-
410
- if ( criteria . memberId ) {
411
- // logger.error(`memberId ${criteria.memberId}`)
412
- const ids = await helper . listChallengesByMember ( criteria . memberId )
413
- // logger.error(`response ${JSON.stringify(ids)}`)
414
- accessQuery . push ( { terms : { _id : ids } } )
415
- }
416
-
417
- if ( accessQuery . length > 0 ) {
418
- mustQuery . push ( {
419
- bool : {
420
- should : accessQuery
421
- }
422
- } )
423
- }
424
-
425
427
if ( boolQuery . length > 0 ) {
426
428
mustQuery . push ( {
427
429
bool : {
@@ -722,6 +724,12 @@ async function createChallenge (currentUser, challenge, userToken) {
722
724
const { track, type } = await validateChallengeData ( challenge )
723
725
if ( _ . get ( type , 'isTask' ) ) {
724
726
_ . set ( challenge , 'task.isTask' , true )
727
+ if ( _ . isUndefined ( _ . get ( challenge , 'task.isAssigned' ) ) ) {
728
+ _ . set ( challenge , 'task.isAssigned' , false )
729
+ }
730
+ if ( _ . isUndefined ( _ . get ( challenge , 'task.memberId' ) ) ) {
731
+ _ . set ( challenge , 'task.memberId' , null )
732
+ }
725
733
}
726
734
if ( challenge . phases && challenge . phases . length > 0 ) {
727
735
await helper . validatePhases ( challenge . phases )
0 commit comments