From 316838136ab0bb8942593a57556556a2aa262e9a Mon Sep 17 00:00:00 2001 From: Thomas Kranitsas Date: Mon, 22 Jun 2020 22:19:09 +0300 Subject: [PATCH] Update business logic behind type/subTrack mapping --- config/default.js | 1 + src/constants.js | 3 ++- src/services/ProcessorService.js | 24 +++++++++++++++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/config/default.js b/config/default.js index 02ff77b..34284d0 100644 --- a/config/default.js +++ b/config/default.js @@ -32,6 +32,7 @@ module.exports = { // Topcoder APIs V5_CHALLENGE_API_URL: process.env.V5_CHALLENGE_API_URL || 'http://localhost:4000/v5/challenges', V5_CHALLENGE_TYPE_API_URL: process.env.V5_CHALLENGE_TYPE_API_URL || 'http://localhost:4000/v5/challenge-types', + V4_CHALLENGE_TYPE_API_URL: process.env.V4_CHALLENGE_TYPE_API_URL || 'http://localhost:4000/v4/challenge-types', V4_CHALLENGE_API_URL: process.env.V4_CHALLENGE_API_URL || 'http://localhost:4000/v4/challenges', V4_TECHNOLOGIES_API_URL: process.env.V4_TECHNOLOGIES_API_URL || 'http://localhost:4000/v4/technologies', V4_PLATFORMS_API_URL: process.env.V4_PLATFORMS_API_URL || 'http://localhost:4000/v4/platforms', diff --git a/src/constants.js b/src/constants.js index 58d435c..2a2164f 100644 --- a/src/constants.js +++ b/src/constants.js @@ -47,7 +47,8 @@ const challengeStatuses = { const challengeAbbreviations = { TASK: 'TASK', - FIRST_2_FINISH: 'FIRST_2_FINISH' + FIRST_2_FINISH: 'FIRST_2_FINISH', + DESIGN_FIRST_2_FINISH: 'DESIGN_FIRST_2_FINISH' } module.exports = { diff --git a/src/services/ProcessorService.js b/src/services/ProcessorService.js index d7163f2..4e80888 100644 --- a/src/services/ProcessorService.js +++ b/src/services/ProcessorService.js @@ -95,14 +95,28 @@ async function parsePayload (payload, m2mToken, isCreated = true) { data.milestoneId = 1 } if (payload.typeId) { - const typeRes = await helper.getRequest(`${config.V5_CHALLENGE_TYPE_API_URL}/${payload.typeId}`, m2mToken) - data.subTrack = typeRes.body.abbreviation // FIXME: thomas + const v5Type = await helper.getRequest(`${config.V5_CHALLENGE_TYPE_API_URL}/${payload.typeId}`, m2mToken) + const v4TypeList = await helper.getRequest(`${config.V4_CHALLENGE_TYPE_API_URL}`, m2mToken) + const v4Type = _.find(_.get(v4TypeList, 'body.result.content', []), type => type.id === v5Type.body.legacyId) + if (!v4Type) { + throw new Error(`There is no mapping between v5 Type ${v5Type.body.name} and V4`) + } + data.subTrack = v4Type.subTrack // TASK is named as FIRST_2_FINISH on legacy - if (data.subTrack === constants.challengeAbbreviations.TASK) { + if (v5Type.body.abbreviation === constants.challengeAbbreviations.TASK) { data.task = true - data.subTrack = constants.challengeAbbreviations.FIRST_2_FINISH + switch (_.toLower(_.toString(data.track))) { + case 'develop': + data.subTrack = constants.challengeAbbreviations.FIRST_2_FINISH + break + case 'design': + data.subTrack = constants.challengeAbbreviations.DESIGN_FIRST_2_FINISH + break + default: + throw new Error(`Cannot create a task for track ${data.track}`) + } } - data.legacyTypeId = typeRes.body.legacyId + data.legacyTypeId = v5Type.body.legacyId } if (payload.description) { try {