Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Update business logic behind type/subTrack mapping #15

Merged
merged 1 commit into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
24 changes: 19 additions & 5 deletions src/services/ProcessorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down