diff --git a/README.md b/README.md index c369b29c..240a62bc 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,7 @@ The following parameters can be set in config files or in env variables: - RESOURCES_API_URL: TC resources API base URL - GROUPS_API_URL: TC groups API base URL - PROJECTS_API_URL: TC projects API base URL +- CHALLENGE_MIGRATION_APP_URL: migration app URL - TERMS_API_URL: TC Terms API Base URL - COPILOT_RESOURCE_ROLE_IDS: copilot resource role ids allowed to upload attachment - HEALTH_CHECK_TIMEOUT: health check timeout in milliseconds diff --git a/config/default.js b/config/default.js index 0ef0a204..9700d193 100644 --- a/config/default.js +++ b/config/default.js @@ -59,6 +59,7 @@ module.exports = { PROJECTS_API_URL: process.env.PROJECTS_API_URL || 'http://localhost:4000/v5/projects', TERMS_API_URL: process.env.TERMS_API_URL || 'http://localhost:4000/v5/terms', CUSTOMER_PAYMENTS_URL: process.env.CUSTOMER_PAYMENTS_URL || 'https://api.topcoder-dev.com/v5/customer-payments', + CHALLENGE_MIGRATION_APP_URL: process.env.CHALLENGE_MIGRATION_APP_URL || 'https://api.topcoder-dev.com/v5/challenge-migration', // copilot resource role ids allowed to upload attachment COPILOT_RESOURCE_ROLE_IDS: process.env.COPILOT_RESOURCE_ROLE_IDS ? process.env.COPILOT_RESOURCE_ROLE_IDS.split(',') : ['10ba038e-48da-487b-96e8-8d3b99b6d18b'], diff --git a/src/common/helper.js b/src/common/helper.js index 0bae077b..c349ecfb 100644 --- a/src/common/helper.js +++ b/src/common/helper.js @@ -463,6 +463,16 @@ async function createSelfServiceProject (name, description, type, token) { return _.get(res, 'data.id') } +/** + * Get project id by roundId + * @param {String} roundId the round id + */ +async function getProjectIdByRoundId (roundId) { + const url = `${config.CHALLENGE_MIGRATION_APP_URL}/getChallengeProjectId/${roundId}` + const res = await axios.get(url) + return _.get(res, 'data.projectId') +} + /** * Get project payment * @param {String} projectId the project id @@ -1292,6 +1302,7 @@ module.exports = { ensureUserCanModifyChallenge, userHasFullAccess, sumOfPrizes, + getProjectIdByRoundId, getGroupById, getChallengeSubmissions, getMemberById, diff --git a/src/controllers/ChallengeController.js b/src/controllers/ChallengeController.js index 02d759f8..b4c87681 100644 --- a/src/controllers/ChallengeController.js +++ b/src/controllers/ChallengeController.js @@ -12,7 +12,17 @@ const logger = require('../common/logger') * @param {Object} res the response */ async function searchChallenges (req, res) { - const result = await service.searchChallenges(req.authUser, { ...req.query, ...req.body }) + let result = await service.searchChallenges(req.authUser, { ...req.query, ...req.body }) + if (!result.total && req.query.legacyId) { + // maybe the legacyId is roundId for mm challenge + // mm challenge use projectId as legacyId + try { + const legacyId = await helper.getProjectIdByRoundId(req.query.legacyId) + result = await service.searchChallenges(req.authUser, { ...req.query, ...req.body, legacyId }) + } catch (e) { + logger.debug(`Failed to get projectId with error: ${e.message}`) + } + } helper.setResHeaders(req, res, result) res.send(result.result) }