@@ -13,6 +13,7 @@ import { setErrorIcon, ERROR_ICON_TYPES } from '../utils/errors';
13
13
import { COMPETITION_TRACKS , getApiResponsePayload } from '../utils/tc' ;
14
14
import { getApi } from './api' ;
15
15
import { getService as getMembersService } from './members' ;
16
+ import { getService as getSubmissionsService } from './submissions' ;
16
17
17
18
export const ORDER_BY = {
18
19
SUBMISSION_END_DATE : 'submissionEndDate' ,
@@ -197,6 +198,7 @@ class ChallengesService {
197
198
tokenV2,
198
199
tokenV3,
199
200
memberService : getMembersService ( ) ,
201
+ submissionsService : getSubmissionsService ( tokenV3 ) ,
200
202
} ;
201
203
}
202
204
@@ -321,8 +323,11 @@ class ChallengesService {
321
323
async getChallengeDetails ( challengeId ) {
322
324
const memberId = this . private . tokenV3 ? decodeToken ( this . private . tokenV3 ) . userId : null ;
323
325
let challenge = { } ;
326
+ let registrants = [ ] ;
327
+ let submissions = [ ] ;
324
328
let isLegacyChallenge = false ;
325
329
let isRegistered = false ;
330
+
326
331
// condition based on ROUTE used for Review Opportunities, change if needed
327
332
if ( / ^ [ \d ] { 5 , 8 } $ / . test ( challengeId ) ) {
328
333
isLegacyChallenge = true ;
@@ -333,28 +338,59 @@ class ChallengesService {
333
338
. then ( res => res . challenges ) ;
334
339
}
335
340
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 ;
341
+ if ( challenge ) {
342
+ registrants = await this . getChallengeRegistrants ( challenge . id ) ;
343
+
344
+ // This TEMP fix to colorStyle, this will be fixed with issue #4530
345
+ registrants = _ . map ( registrants , r => ( {
346
+ ...r , colorStyle : 'color: #151516' ,
347
+ } ) ) ;
348
+
349
+ /* Prepare data to logged user */
350
+ if ( memberId ) {
351
+ isRegistered = _ . some ( registrants , r => r . memberId === memberId ) ;
352
+
353
+ /**
354
+ * TODO: Currenlty using legacyId until submissions_api fix issue with UUID
355
+ */
356
+ const subParams = {
357
+ challengeId : challenge . legacyId ,
358
+ perPage : 100 ,
359
+ } ;
360
+ submissions = await this . private . submissionsService . getSubmissions ( subParams ) ;
361
+
362
+ if ( submissions ) {
363
+ // Remove AV Scan, SonarQube Review and Virus Scan review types
364
+ const reviewScans = await this . private . submissionsService . getScanReviewIds ( ) ;
365
+ submissions . forEach ( ( s , i ) => {
366
+ submissions [ i ] . review = _ . reject ( s . review , r => r && _ . includes ( reviewScans , r . typeId ) ) ;
367
+ } ) ;
368
+
369
+ // Add submission date to registrants
370
+ registrants . forEach ( ( r , i ) => {
371
+ const submission = submissions . find ( s => s . memberId === Number ( r . memberId ) ) ;
372
+ if ( submission ) {
373
+ registrants [ i ] . submissionDate = submission . created ;
374
+ }
375
+ } ) ;
376
+ }
377
+ }
342
378
343
- if ( memberId ) {
344
- isRegistered = _ . some ( registrants , r => r . memberId === memberId ) ;
379
+ challenge = {
380
+ ...challenge ,
381
+ isLegacyChallenge,
382
+ isRegistered,
383
+ registrants,
384
+ submissions,
385
+ events : _ . map ( challenge . events , e => ( {
386
+ eventName : e . key ,
387
+ eventId : e . id ,
388
+ description : e . name ,
389
+ } ) ) ,
390
+ fetchedWithAuth : Boolean ( this . private . apiV5 . private . token ) ,
391
+ } ;
345
392
}
346
393
347
- challenge . isLegacyChallenge = isLegacyChallenge ;
348
- challenge . isRegistered = isRegistered ;
349
-
350
- challenge . events = _ . map ( challenge . events , e => ( {
351
- eventName : e . key ,
352
- eventId : e . id ,
353
- description : e . name ,
354
- } ) ) ;
355
-
356
- challenge . fetchedWithAuth = Boolean ( this . private . apiV5 . private . token ) ;
357
-
358
394
return challenge ;
359
395
}
360
396
@@ -481,6 +517,16 @@ class ChallengesService {
481
517
} ;
482
518
}
483
519
520
+ /**
521
+ * Gets user resources.
522
+ * @param {String } userId User id whose challenges we want to fetch.
523
+ * @return {Promise } Resolves to the api response.
524
+ */
525
+ async getUserResources ( userId ) {
526
+ const res = await this . private . apiV5 . get ( `/resources/${ userId } /challenges` ) ;
527
+ return res . json ( ) ;
528
+ }
529
+
484
530
/**
485
531
* Gets marathon matches of the specified user.
486
532
* @param {String } memberId User whose challenges we want to fetch.
0 commit comments