@@ -14,6 +14,7 @@ import { COMPETITION_TRACKS, getApiResponsePayload } from '../utils/tc';
14
14
import { getApi } from './api' ;
15
15
import { getService as getMembersService } from './members' ;
16
16
import { getService as getSubmissionsService } from './submissions' ;
17
+ import mockRecommendedChallenges from './__mocks__/data/recommended-challenges.json' ;
17
18
18
19
export function getFilterUrl ( backendFilter , frontFilter ) {
19
20
const ff = _ . clone ( frontFilter ) ;
@@ -185,6 +186,7 @@ class ChallengesService {
185
186
totalCount : res . headers ? res . headers . get ( 'x-total' ) : 0 ,
186
187
meta : {
187
188
allChallengesCount : res . headers ? res . headers . get ( 'x-total' ) : 0 ,
189
+ allRecommendedChallengesCount : 0 ,
188
190
myChallengesCount : 0 ,
189
191
ongoingChallengesCount : 0 ,
190
192
openChallengesCount : 0 ,
@@ -474,12 +476,21 @@ class ChallengesService {
474
476
* @return {Promise } Resolves to the array of subtrack names.
475
477
*/
476
478
getChallengeTypes ( ) {
479
+ const recommended = {
480
+ id : 'e06b074d-43c2-4e7e-9cd3-c43e13d51b40' ,
481
+ name : 'Recommended' ,
482
+ description : "Available challenges that match competitor's skills" ,
483
+ isActive : true ,
484
+ isTask : false ,
485
+ abbreviation : 'REC' ,
486
+ } ;
487
+
477
488
return this . private . apiV5 . get ( '/challenge-types' )
478
489
. then ( res => ( res . ok ? res . json ( ) : new Error ( res . statusText ) ) )
479
490
. then ( res => (
480
491
res . message
481
492
? new Error ( res . message )
482
- : res
493
+ : [ ... res , recommended ]
483
494
) ) ;
484
495
}
485
496
@@ -527,6 +538,38 @@ class ChallengesService {
527
538
} ) ;
528
539
}
529
540
541
+ /**
542
+ * TODO: Integrate with real API.
543
+ * Gets recommended challenges.
544
+ * @param {Object } sort
545
+ * @param {Object } filter
546
+ * @return {Promise } Resolves to the api response.
547
+ */
548
+ async getRecommendedChallenges ( sort , filter ) {
549
+ let sortedChallenges = [ ] ;
550
+ const tracks = [ ] ;
551
+ if ( filter . tracks . DS ) tracks . push ( 'Data Science' ) ;
552
+ if ( filter . tracks . Des ) tracks . push ( 'Design' ) ;
553
+ if ( filter . tracks . Dev ) tracks . push ( 'Development' ) ;
554
+ if ( filter . tracks . QA ) tracks . push ( 'Quality Assurance' ) ;
555
+ if ( filter . openForRegistration === 'best-match' || sort . openForRegistration === { } ) {
556
+ sortedChallenges = _ . sortBy ( mockRecommendedChallenges , [ 'matchScore' ] ) ;
557
+ } else {
558
+ sortedChallenges = _ . sortBy ( mockRecommendedChallenges , [ sort . openForRegistration ] ) ;
559
+ }
560
+
561
+ const filteredChallenges = sortedChallenges . filter ( item => tracks . includes ( item . track ) ) ;
562
+ const mockResponse = _ . clone ( this . private . tokenV3 ? filteredChallenges : [ ] ) ;
563
+
564
+ const sleep = m => new Promise ( r => setTimeout ( r , m ) ) ;
565
+ await sleep ( 1000 ) ;
566
+
567
+ return Promise . resolve ( {
568
+ challenges : mockResponse ,
569
+ meta : mockResponse . length ,
570
+ } ) ;
571
+ }
572
+
530
573
/**
531
574
* Gets SRM matches.
532
575
* @param {Object } params
0 commit comments