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

Commit 5c041ed

Browse files
add support for groups
1 parent 988533f commit 5c041ed

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

ReadMe.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The following parameters can be set in config files or in env variables:
5050
- V4_TECHNOLOGIES_API_URL: v4 technologies api url, default value is 'http://localhost:4000/v4/technologies'
5151
- V4_PLATFORMS_API_URL: v4 platforms api url, default value is 'http://localhost:4000/v4/platforms'
5252
- V5_CHALLENGE_MIGRATION_API_URL: v5 challenge migration API URL, default value is https://api.topcoder-dev.com/v5/challenge-migration
53-
53+
- V5_GROUPS_API_URL: v5 groups API URL, default value is https://api.topcoder-dev.com/v5/groups
5454
There is a `/health` endpoint that checks for the health of the app. This sets up an expressjs server and listens on the environment variable `PORT`. It's not part of the configuration file and needs to be passed as an environment variable
5555

5656
Configuration for the tests is at `config/test.js`, only add such new configurations different from `config/default.js`

config/default.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ module.exports = {
3939
V5_PROJECTS_API_URL: process.env.V5_PROJECTS_API_URL || 'https://api.topcoder-dev.com/v5/projects',
4040
V5_CHALLENGE_MIGRATION_API_URL: process.env.V5_CHALLENGE_MIGRATION_API_URL || 'https://api.topcoder-dev.com/v5/challenge-migration',
4141

42+
V5_GROUPS_API_URL: process.env.V5_GROUPS_API_URL || 'https://api.topcoder-dev.com/v5/groups',
43+
4244
// PHASE IDs
4345
REGISTRATION_PHASE_ID: process.env.REGISTRATION_PHASE_ID || 'a93544bc-c165-4af4-b55e-18f3593b457a',
4446
SUBMISSION_PHASE_ID: process.env.SUBMISSION_PHASE_ID || '6950164f-3c5e-4bdc-abc8-22aaf5a1bd49',

src/services/ProcessorService.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ const constants = require('../constants')
1414
// const showdown = require('showdown')
1515
// const converter = new showdown.Converter()
1616

17+
/**
18+
* Get group information by V5 UUID
19+
* @param {String} v5GroupId the v5 group UUID
20+
* @param {String} m2mToken token for accessing the API
21+
*/
22+
async function getGroup (v5GroupId, m2mToken) {
23+
const response = await helper.getRequest(`${config.V5_GROUPS_API_URL}/${v5GroupId}`, m2mToken)
24+
return response.body
25+
}
26+
1727
/**
1828
* Get technologies from V4 API
1929
* @param {String} m2mToken token for accessing the API
@@ -188,6 +198,22 @@ async function parsePayload (payload, m2mToken, isCreated = true) {
188198
const platResult = await getPlatforms(m2mToken)
189199
data.platforms = _.filter(platResult.result.content, e => payload.tags.includes(e.name))
190200
}
201+
if (payload.groups && _.get(payload, 'groups.length', 0) > 0) {
202+
const legacyGroups = []
203+
for (const group of payload.groups) {
204+
try {
205+
const groupInfo = await getGroup(group, m2mToken)
206+
if (!_.isEmpty(_.get(groupInfo, 'oldId'))) {
207+
legacyGroups.push(_.get(groupInfo, 'oldId'))
208+
}
209+
} catch (e) {
210+
logger.warn(`Failed to load details for group ${group}`)
211+
}
212+
}
213+
if (legacyGroups.length > 0) {
214+
data.groups = legacyGroups
215+
}
216+
}
191217
return data
192218
} catch (err) {
193219
// Debugging
@@ -297,6 +323,7 @@ processCreate.schema = {
297323
projectId: Joi.number().integer().positive().required(),
298324
copilotId: Joi.number().integer().positive().optional(),
299325
status: Joi.string().valid(_.values(Object.keys(constants.createChallengeStatusesMap))).required(),
326+
groups: Joi.array().items(Joi.string()),
300327
startDate: Joi.date()
301328
}).unknown(true).required()
302329
}).required()
@@ -416,6 +443,7 @@ processUpdate.schema = {
416443
}).unknown(true)).min(1),
417444
tags: Joi.array().items(Joi.string().required()).min(1), // tag names
418445
projectId: Joi.number().integer().positive().allow(null),
446+
groups: Joi.array().items(Joi.string()),
419447
startDate: Joi.date()
420448
}).unknown(true).required()
421449
}).required()

0 commit comments

Comments
 (0)