@@ -146,18 +146,12 @@ class ChallengesService {
146
146
} ;
147
147
const url = `${ endpoint } ?${ qs . stringify ( query ) } ` ;
148
148
const res = await this . private . apiV5 . get ( url ) . then ( checkErrorV5 ) ;
149
- let myChallenges ;
150
- if ( typeof this . private . tokenV3 !== 'undefined' ) {
151
- const { userId } = decodeToken ( this . private . tokenV3 ) ;
152
- myChallenges = await this . private . apiV5 . get ( `/resources/${ userId } /challenges` )
153
- . then ( checkErrorV5 ) . then ( userChallenges => userChallenges ) ;
154
- }
155
149
return {
156
150
challenges : res . result || [ ] ,
157
151
totalCount : res . headers . get ( 'x-total' ) ,
158
152
meta : {
159
153
allChallengesCount : res . headers . get ( 'x-total' ) ,
160
- myChallengesCount : ( myChallenges && myChallenges . headers . get ( 'x-total' ) ) || 0 ,
154
+ myChallengesCount : 0 ,
161
155
ongoingChallengesCount : 0 ,
162
156
openChallengesCount : 0 ,
163
157
totalCount : res . headers . get ( 'x-total' ) ,
@@ -339,18 +333,15 @@ class ChallengesService {
339
333
. then ( res => res . challenges ) ;
340
334
}
341
335
342
- // TEMP FIX until API was fixed
343
- try {
344
- const registrants = await this . getChallengeRegistrants ( challenge . id ) ;
345
- challenge . registrants = registrants ;
346
- } catch ( err ) {
347
- challenge . registrants = [ ] ;
348
- }
336
+ let registrants = await this . getChallengeRegistrants ( challenge . id ) ;
337
+ // This TEMP fix to colorStyle, this will be fixed with issue #4530
338
+ registrants = _ . map ( registrants , r => ( {
339
+ ...r , colorStyle : 'color: #151516' ,
340
+ } ) ) ;
341
+ challenge . registrants = registrants ;
349
342
350
343
if ( memberId ) {
351
- const userChallenges = await this . private . apiV5 . get ( `/resources/${ memberId } /challenges` )
352
- . then ( checkErrorV5 ) . then ( res => res . result ) ;
353
- isRegistered = _ . includes ( userChallenges , challengeId ) ;
344
+ isRegistered = _ . some ( registrants , r => r . memberId === memberId ) ;
354
345
}
355
346
356
347
challenge . isLegacyChallenge = isLegacyChallenge ;
@@ -373,19 +364,15 @@ class ChallengesService {
373
364
* @return {Promise } Resolves to the challenge registrants array.
374
365
*/
375
366
async getChallengeRegistrants ( challengeId ) {
376
- const roleId = await this . getRoleId ( ' Submitter' ) ;
367
+ /* If no token provided, resource will return Submitter role only */
377
368
const params = {
378
369
challengeId,
379
- roleId,
370
+ roleId : this . private . tokenV3 ? await this . getRoleId ( 'Submitter' ) : '' ,
380
371
} ;
381
372
382
373
const registrants = await this . private . apiV5 . get ( `/resources?${ qs . stringify ( params ) } ` )
383
374
. then ( checkErrorV5 ) . then ( res => res . result ) ;
384
375
385
- if ( _ . isEmpty ( registrants ) ) {
386
- throw new Error ( 'Resource Role not found!' ) ;
387
- }
388
-
389
376
return registrants || [ ] ;
390
377
}
391
378
@@ -440,16 +427,9 @@ class ChallengesService {
440
427
* @return {Promise } Resolves to the api response.
441
428
*/
442
429
async getChallenges ( filters , params ) {
443
- const memberId = this . private . tokenV3 ? decodeToken ( this . private . tokenV3 ) . userId : null ;
444
- let userChallenges = [ ] ;
445
- if ( memberId ) {
446
- userChallenges = await this . private . apiV5 . get ( `/resources/${ memberId } /challenges` )
447
- . then ( checkErrorV5 ) . then ( res => res . result ) ;
448
- }
449
430
return this . private . getChallenges ( '/challenges/' , filters , params )
450
431
. then ( ( res ) => {
451
- res . challenges . forEach ( item => normalizeChallenge ( item ,
452
- userChallenges . includes ( item . id ) ? memberId : null ) ) ;
432
+ res . challenges . forEach ( item => normalizeChallenge ( item ) ) ;
453
433
return res ;
454
434
} ) ;
455
435
}
0 commit comments