Skip to content

Commit 127c845

Browse files
authored
Merge pull request #300 from nursoltan-s/nursoltan/final-fixes
integrate recommendation challenges with api
2 parents c5a7697 + 9228fd3 commit 127c845

File tree

2 files changed

+28
-85
lines changed

2 files changed

+28
-85
lines changed

src/services/__mocks__/data/recommended-challenges.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/services/challenges.js

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { COMPETITION_TRACKS, getApiResponsePayload } from '../utils/tc';
1414
import { getApi } from './api';
1515
import { getService as getMembersService } from './members';
1616
import { getService as getSubmissionsService } from './submissions';
17-
import mockRecommendedChallenges from './__mocks__/data/recommended-challenges.json';
1817

1918
export function getFilterUrl(backendFilter, frontFilter) {
2019
const ff = _.clone(frontFilter);
@@ -476,21 +475,12 @@ class ChallengesService {
476475
* @return {Promise} Resolves to the array of subtrack names.
477476
*/
478477
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-
488478
return this.private.apiV5.get('/challenge-types')
489479
.then(res => (res.ok ? res.json() : new Error(res.statusText)))
490480
.then(res => (
491481
res.message
492482
? new Error(res.message)
493-
: [...res, recommended]
483+
: res
494484
));
495485
}
496486

@@ -542,49 +532,36 @@ class ChallengesService {
542532
* Gets challenges.
543533
* @param {Object} filters Optional.
544534
* @param {Object} params Optional.
535+
* @param {String} handle user handle
545536
* @return {Promise} Resolves to the api response.
546537
*/
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);
582551

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+
};
588565
}
589566

590567
/**

0 commit comments

Comments
 (0)