@@ -14,7 +14,6 @@ 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' ;
18
17
19
18
export function getFilterUrl ( backendFilter , frontFilter ) {
20
19
const ff = _ . clone ( frontFilter ) ;
@@ -476,21 +475,12 @@ class ChallengesService {
476
475
* @return {Promise } Resolves to the array of subtrack names.
477
476
*/
478
477
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
-
488
478
return this . private . apiV5 . get ( '/challenge-types' )
489
479
. then ( res => ( res . ok ? res . json ( ) : new Error ( res . statusText ) ) )
490
480
. then ( res => (
491
481
res . message
492
482
? new Error ( res . message )
493
- : [ ... res , recommended ]
483
+ : res
494
484
) ) ;
495
485
}
496
486
@@ -542,49 +532,36 @@ class ChallengesService {
542
532
* Gets challenges.
543
533
* @param {Object } filters Optional.
544
534
* @param {Object } params Optional.
535
+ * @param {String } handle user handle
545
536
* @return {Promise } Resolves to the api response.
546
537
*/
547
- async getRecommendedChallenges ( sort , filter ) {
548
- return this . private . getChallenges ( '/challenges/' , {
549
- frontFilter : { ...filter , types : [ 'TSK' , 'CH' , 'F2F' ] } ,
550
- } )
551
- . then ( ( res ) => {
552
- res . challenges . forEach ( item => normalizeChallenge ( item ) ) ;
553
- let sortedChallenges = [ ] ;
554
- const challenges = res . challenges . slice ( 0 , 8 ) . map ( ( item , index ) => ( {
555
- ...item ,
556
- matchScore : mockRecommendedChallenges [ index ] . matchScore ,
557
- } ) ) ;
558
-
559
- const tracks = [ ] ;
560
- const types = [ ] ;
561
- if ( filter . types . includes ( 'CH' ) ) types . push ( 'Challenge' ) ;
562
- if ( filter . types . includes ( 'F2F' ) ) types . push ( 'First2Finish' ) ;
563
- if ( filter . types . includes ( 'TSK' ) ) types . push ( 'Task' ) ;
564
-
565
- if ( filter . tracks . DS ) tracks . push ( 'Data Science' ) ;
566
- if ( filter . tracks . Des ) tracks . push ( 'Design' ) ;
567
- if ( filter . tracks . Dev ) tracks . push ( 'Development' ) ;
568
- if ( filter . tracks . QA ) tracks . push ( 'Quality Assurance' ) ;
569
- if ( sort . openForRegistration === 'bestMatch' || sort . openForRegistration === { } ) {
570
- const ascArray = _ . sortBy ( challenges , [
571
- item => Math . trunc ( ( parseFloat ( item . matchScore ) + 1.0 ) / 2.0 * 100.0 ) ] ) ;
572
- sortedChallenges = _ . reverse ( ascArray ) ;
573
- } else if ( sort . openForRegistration === 'name' ) {
574
- sortedChallenges = _ . sortBy ( challenges , [ 'name' ] ) ;
575
- } else {
576
- sortedChallenges = _ . sortBy ( challenges , [ sort . openForRegistration ] ) ;
577
- }
578
-
579
- let filteredChallenges = sortedChallenges . filter ( item => tracks . includes ( item . track ) ) ;
580
- filteredChallenges = filteredChallenges . filter ( item => types . includes ( item . type ) ) ;
581
- const mockResponse = _ . clone ( this . private . tokenV3 ? filteredChallenges : [ ] ) ;
538
+ async getRecommendedChallenges ( filter , handle ) {
539
+ const query = getFilterUrl (
540
+ filter . backendFilter ,
541
+ { ...filter . frontFilter , per_page : filter . frontFilter . perPage } ,
542
+ ) ;
543
+
544
+ let res = { } ;
545
+ if ( _ . some ( filter . frontFilter . tracks , val => val )
546
+ && ! _ . isEqual ( filter . frontFilter . types , [ ] ) ) {
547
+ const url = `/recommender-api/${ handle } ?${ query } ` ;
548
+ res = await this . private . apiV5 . get ( url ) . then ( checkErrorV5 ) ;
549
+ }
550
+ const challenges = res . result . filter ( ch => ch . jaccard_index > 0 ) ;
582
551
583
- return {
584
- challenges : mockResponse ,
585
- meta : mockResponse . length ,
586
- } ;
587
- } ) ;
552
+ const totalCount = challenges . length ;
553
+ return {
554
+ challenges,
555
+ totalCount,
556
+ meta : {
557
+ allChallengesCount : challenges . length ,
558
+ allRecommendedChallengesCount : 0 ,
559
+ myChallengesCount : 0 ,
560
+ ongoingChallengesCount : 0 ,
561
+ openChallengesCount : 0 ,
562
+ totalCount,
563
+ } ,
564
+ } ;
588
565
}
589
566
590
567
/**
0 commit comments