@@ -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' ,
@@ -203,6 +204,7 @@ class ChallengesService {
203
204
tokenV2,
204
205
tokenV3,
205
206
memberService : getMembersService ( ) ,
207
+ submissionsService : getSubmissionsService ( tokenV3 ) ,
206
208
} ;
207
209
}
208
210
@@ -327,8 +329,11 @@ class ChallengesService {
327
329
async getChallengeDetails ( challengeId ) {
328
330
const memberId = this . private . tokenV3 ? decodeToken ( this . private . tokenV3 ) . userId : null ;
329
331
let challenge = { } ;
332
+ let registrants = [ ] ;
333
+ let submissions = [ ] ;
330
334
let isLegacyChallenge = false ;
331
335
let isRegistered = false ;
336
+
332
337
// condition based on ROUTE used for Review Opportunities, change if needed
333
338
if ( / ^ [ \d ] { 5 , 8 } $ / . test ( challengeId ) ) {
334
339
isLegacyChallenge = true ;
@@ -339,28 +344,59 @@ class ChallengesService {
339
344
. then ( res => res . challenges ) ;
340
345
}
341
346
342
- let registrants = await this . getChallengeRegistrants ( challenge . id ) ;
343
- // This TEMP fix to colorStyle, this will be fixed with issue #4530
344
- registrants = _ . map ( registrants , r => ( {
345
- ...r , colorStyle : 'color: #151516' ,
346
- } ) ) ;
347
- challenge . registrants = registrants ;
347
+ if ( challenge ) {
348
+ registrants = await this . getChallengeRegistrants ( challenge . id ) ;
349
+
350
+ // This TEMP fix to colorStyle, this will be fixed with issue #4530
351
+ registrants = _ . map ( registrants , r => ( {
352
+ ...r , colorStyle : 'color: #151516' ,
353
+ } ) ) ;
354
+
355
+ /* Prepare data to logged user */
356
+ if ( memberId ) {
357
+ isRegistered = _ . some ( registrants , r => r . memberId === memberId ) ;
358
+
359
+ /**
360
+ * TODO: Currenlty using legacyId until submissions_api fix issue with UUID
361
+ */
362
+ const subParams = {
363
+ challengeId : challenge . legacyId ,
364
+ perPage : 100 ,
365
+ } ;
366
+ submissions = await this . private . submissionsService . getSubmissions ( subParams ) ;
367
+
368
+ if ( submissions ) {
369
+ // Remove AV Scan, SonarQube Review and Virus Scan review types
370
+ const reviewScans = await this . private . submissionsService . getScanReviewIds ( ) ;
371
+ submissions . forEach ( ( s , i ) => {
372
+ submissions [ i ] . review = _ . reject ( s . review , r => _ . includes ( reviewScans , r . typeId ) ) ;
373
+ } ) ;
374
+
375
+ // Add submission date to registrants
376
+ registrants . forEach ( ( r , i ) => {
377
+ const submission = submissions . find ( s => s . memberId === Number ( r . memberId ) ) ;
378
+ if ( submission ) {
379
+ registrants [ i ] . submissionDate = submission . created ;
380
+ }
381
+ } ) ;
382
+ }
383
+ }
348
384
349
- if ( memberId ) {
350
- isRegistered = _ . some ( registrants , r => r . memberId === memberId ) ;
385
+ challenge = {
386
+ ...challenge ,
387
+ isLegacyChallenge,
388
+ isRegistered,
389
+ registrants,
390
+ submissions,
391
+ events : _ . map ( challenge . events , e => ( {
392
+ eventName : e . key ,
393
+ eventId : e . id ,
394
+ description : e . name ,
395
+ } ) ) ,
396
+ fetchedWithAuth : Boolean ( this . private . apiV5 . private . token ) ,
397
+ } ;
351
398
}
352
399
353
- challenge . isLegacyChallenge = isLegacyChallenge ;
354
- challenge . isRegistered = isRegistered ;
355
-
356
- challenge . events = _ . map ( challenge . events , e => ( {
357
- eventName : e . key ,
358
- eventId : e . id ,
359
- description : e . name ,
360
- } ) ) ;
361
-
362
- challenge . fetchedWithAuth = Boolean ( this . private . apiV5 . private . token ) ;
363
-
364
400
return challenge ;
365
401
}
366
402
0 commit comments