Skip to content

Commit 2e2db18

Browse files
Merge pull request #512 from topcoder-platform/Topgear-check-challenge
support a checkIfExists query parameter
2 parents 86ff56a + fc0b7cd commit 2e2db18

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/controllers/ChallengeController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function sendNotifications (req, res) {
5454
* @param {Object} res the response
5555
*/
5656
async function getChallenge (req, res) {
57-
const result = await service.getChallenge(req.authUser, req.params.challengeId)
57+
const result = await service.getChallenge(req.authUser, req.params.challengeId, req.query.checkIfExists)
5858
res.send(result)
5959
}
6060

src/services/ChallengeService.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,9 +1245,10 @@ async function getPhasesAndPopulate (data) {
12451245
* Get challenge.
12461246
* @param {Object} currentUser the user who perform operation
12471247
* @param {String} id the challenge id
1248+
* @param {Boolean} checkIfExists flag to check if challenge exists
12481249
* @returns {Object} the challenge with given id
12491250
*/
1250-
async function getChallenge (currentUser, id) {
1251+
async function getChallenge (currentUser, id, checkIfExists) {
12511252
const span = await logger.startSpan('ChallengeService.getChallenge')
12521253
// get challenge from Elasticsearch
12531254
let challenge
@@ -1272,6 +1273,10 @@ async function getChallenge (currentUser, id) {
12721273
throw e
12731274
}
12741275
}
1276+
if (checkIfExists) {
1277+
return _.pick(challenge, ['id', 'legacyId'])
1278+
}
1279+
12751280
await helper.ensureUserCanViewChallenge(currentUser, challenge)
12761281

12771282
// // FIXME: Temporarily hard coded as the migrad
@@ -1318,7 +1323,8 @@ async function getChallenge (currentUser, id) {
13181323

13191324
getChallenge.schema = {
13201325
currentUser: Joi.any(),
1321-
id: Joi.id()
1326+
id: Joi.id(),
1327+
checkIfExists: Joi.boolean()
13221328
}
13231329

13241330
/**

0 commit comments

Comments
 (0)