Skip to content

Commit f8c6893

Browse files
committed
feat: search mm challenge by roundId
1 parent 6582d21 commit f8c6893

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

README.md

+1
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

+1
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

+13-2
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,25 @@ async function createSelfServiceProject (name, description, type, token) {
456456
type
457457
}
458458
const url = `${config.PROJECTS_API_URL}`
459-
const res = await axios.post(url, projectObj, {headers: {Authorization: `Bearer ${token}`}})
459+
const res = await axios.post(url, projectObj, { headers: { Authorization: `Bearer ${token}` } })
460460
return _.get(res, 'data.id')
461461
}
462462

463+
/**
464+
* Get project id by roundId
465+
* @param {String} roundId the round id
466+
*/
467+
async function getProjectIdByRoundId (roundId) {
468+
const url = `${config.CHALLENGE_MIGRATION_APP_URL}/getChallengeProjectId/${roundId}`
469+
const res = await axios.get(url)
470+
return _.get(res, 'data.projectId')
471+
}
472+
463473
/**
464474
* Get project payment
465475
* @param {String} projectId the project id
466476
*/
467-
async function getProjectPayment (projectId) {
477+
async function getProjectPayment (projectId) {
468478
const token = await getM2MToken()
469479
const url = `${config.CUSTOMER_PAYMENTS_URL}`
470480
const res = await axios.get(url, {
@@ -1275,6 +1285,7 @@ module.exports = {
12751285
ensureUserCanModifyChallenge,
12761286
userHasFullAccess,
12771287
sumOfPrizes,
1288+
getProjectIdByRoundId,
12781289
getGroupById,
12791290
getChallengeSubmissions,
12801291
getMemberById,

src/controllers/ChallengeController.js

+11-1
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)