@@ -11,7 +11,7 @@ import { decodeToken } from 'tc-accounts';
11
11
import logger from '../utils/logger' ;
12
12
import { setErrorIcon , ERROR_ICON_TYPES } from '../utils/errors' ;
13
13
import { COMPETITION_TRACKS , getApiResponsePayload } from '../utils/tc' ;
14
- import { getApi , proxyApi } from './api' ;
14
+ import { getApi } from './api' ;
15
15
import { getService as getMembersService } from './members' ;
16
16
17
17
export const ORDER_BY = {
@@ -200,7 +200,6 @@ class ChallengesService {
200
200
apiV3 : getApi ( 'V3' , tokenV3 ) ,
201
201
getChallenges,
202
202
getMemberChallenges,
203
- proxyApi,
204
203
tokenV2,
205
204
tokenV3,
206
205
memberService : getMembersService ( ) ,
@@ -326,8 +325,10 @@ class ChallengesService {
326
325
* @return {Promise } Resolves to the challenge object.
327
326
*/
328
327
async getChallengeDetails ( challengeId ) {
328
+ const user = decodeToken ( this . private . tokenV3 ) ;
329
329
let challenge = { } ;
330
330
let isLegacyChallenge = false ;
331
+ let isRegistered = false ;
331
332
// condition based on ROUTE used for Review Opportunities, change if needed
332
333
if ( / ^ [ \d ] { 5 , 8 } $ / . test ( challengeId ) ) {
333
334
isLegacyChallenge = true ;
@@ -338,10 +339,22 @@ class ChallengesService {
338
339
. then ( res => res . challenges ) ;
339
340
}
340
341
341
- const registrants = await this . getChallengeRegistrants ( challenge . id ) ;
342
- challenge . registrants = registrants ;
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
+ }
349
+
350
+ if ( user ) {
351
+ const userChallenges = await this . private . apiV5 . get ( `/resources/${ user . userId } /challenges` )
352
+ . then ( checkErrorV5 ) . then ( res => res . result ) ;
353
+ isRegistered = _ . includes ( userChallenges , challengeId ) ;
354
+ }
343
355
344
356
challenge . isLegacyChallenge = isLegacyChallenge ;
357
+ challenge . isRegistered = isRegistered ;
345
358
346
359
challenge . events = _ . map ( challenge . events , e => ( {
347
360
eventName : e . key ,
@@ -360,7 +373,19 @@ class ChallengesService {
360
373
* @return {Promise } Resolves to the challenge registrants array.
361
374
*/
362
375
async getChallengeRegistrants ( challengeId ) {
363
- const registrants = await this . private . proxyApi ( `/challenges/${ challengeId } /registrants` ) ;
376
+ const roleId = await this . getRoleId ( 'Submitter' ) ;
377
+ const params = {
378
+ challengeId,
379
+ roleId,
380
+ } ;
381
+
382
+ const registrants = await this . private . apiV5 . get ( `/resources?${ qs . stringify ( params ) } ` )
383
+ . then ( checkErrorV5 ) . then ( res => res . result ) ;
384
+
385
+ if ( _ . isEmpty ( registrants ) ) {
386
+ throw new Error ( 'Resource Role not found!' ) ;
387
+ }
388
+
364
389
return registrants || [ ] ;
365
390
}
366
391
@@ -519,8 +544,10 @@ class ChallengesService {
519
544
async getRoleId ( roleName ) {
520
545
const params = {
521
546
name : roleName ,
547
+ isActive : true ,
522
548
} ;
523
- const roles = await this . private . proxyApi ( `/challenges/roleId?${ qs . stringify ( params ) } ` ) ;
549
+ const roles = await this . private . apiV5 . get ( `/resource-roles?${ qs . stringify ( params ) } ` )
550
+ . then ( checkErrorV5 ) . then ( res => res . result ) ;
524
551
525
552
if ( _ . isEmpty ( roles ) ) {
526
553
throw new Error ( 'Resource Role not found!' ) ;
0 commit comments