Skip to content

Commit 01caefb

Browse files
authored
Merge pull request #514 from yoution/master
Revert "Merge pull request #495 from topcoder-platform/revert-494-fea…
2 parents bc39ec2 + 248a6ea commit 01caefb

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ The following parameters can be set in config files or in env variables:
6464
- RESOURCES_API_URL: TC resources API base URL
6565
- GROUPS_API_URL: TC groups API base URL
6666
- PROJECTS_API_URL: TC projects API base URL
67+
- CHALLENGE_MIGRATION_APP_URL: migration app URL
6768
- TERMS_API_URL: TC Terms API Base URL
6869
- COPILOT_RESOURCE_ROLE_IDS: copilot resource role ids allowed to upload attachment
6970
- HEALTH_CHECK_TIMEOUT: health check timeout in milliseconds

config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module.exports = {
5959
PROJECTS_API_URL: process.env.PROJECTS_API_URL || 'http://localhost:4000/v5/projects',
6060
TERMS_API_URL: process.env.TERMS_API_URL || 'http://localhost:4000/v5/terms',
6161
CUSTOMER_PAYMENTS_URL: process.env.CUSTOMER_PAYMENTS_URL || 'https://api.topcoder-dev.com/v5/customer-payments',
62+
CHALLENGE_MIGRATION_APP_URL: process.env.CHALLENGE_MIGRATION_APP_URL || 'https://api.topcoder-dev.com/v5/challenge-migration',
6263
// copilot resource role ids allowed to upload attachment
6364
COPILOT_RESOURCE_ROLE_IDS: process.env.COPILOT_RESOURCE_ROLE_IDS
6465
? process.env.COPILOT_RESOURCE_ROLE_IDS.split(',') : ['10ba038e-48da-487b-96e8-8d3b99b6d18b'],

src/common/helper.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,16 @@ async function createSelfServiceProject (name, description, type, token) {
463463
return _.get(res, 'data.id')
464464
}
465465

466+
/**
467+
* Get project id by roundId
468+
* @param {String} roundId the round id
469+
*/
470+
async function getProjectIdByRoundId (roundId) {
471+
const url = `${config.CHALLENGE_MIGRATION_APP_URL}/getChallengeProjectId/${roundId}`
472+
const res = await axios.get(url)
473+
return _.get(res, 'data.projectId')
474+
}
475+
466476
/**
467477
* Get project payment
468478
* @param {String} projectId the project id
@@ -1292,6 +1302,7 @@ module.exports = {
12921302
ensureUserCanModifyChallenge,
12931303
userHasFullAccess,
12941304
sumOfPrizes,
1305+
getProjectIdByRoundId,
12951306
getGroupById,
12961307
getChallengeSubmissions,
12971308
getMemberById,

src/controllers/ChallengeController.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@ const logger = require('../common/logger')
1212
* @param {Object} res the response
1313
*/
1414
async function searchChallenges (req, res) {
15-
const result = await service.searchChallenges(req.authUser, { ...req.query, ...req.body })
15+
let result = await service.searchChallenges(req.authUser, { ...req.query, ...req.body })
16+
if (!result.total && req.query.legacyId) {
17+
// maybe the legacyId is roundId for mm challenge
18+
// mm challenge use projectId as legacyId
19+
try {
20+
const legacyId = await helper.getProjectIdByRoundId(req.query.legacyId)
21+
result = await service.searchChallenges(req.authUser, { ...req.query, ...req.body, legacyId })
22+
} catch (e) {
23+
logger.debug(`Failed to get projectId with error: ${e.message}`)
24+
}
25+
}
1626
helper.setResHeaders(req, res, result)
1727
res.send(result.result)
1828
}

0 commit comments

Comments
 (0)