diff --git a/src/controllers/ChallengeController.js b/src/controllers/ChallengeController.js index 5c715c92..acbd45c2 100644 --- a/src/controllers/ChallengeController.js +++ b/src/controllers/ChallengeController.js @@ -54,7 +54,7 @@ async function sendNotifications (req, res) { * @param {Object} res the response */ async function getChallenge (req, res) { - const result = await service.getChallenge(req.authUser, req.params.challengeId) + const result = await service.getChallenge(req.authUser, req.params.challengeId, req.query.checkIfExists) res.send(result) } diff --git a/src/services/ChallengeService.js b/src/services/ChallengeService.js index 49d42439..56eff160 100644 --- a/src/services/ChallengeService.js +++ b/src/services/ChallengeService.js @@ -1245,9 +1245,10 @@ async function getPhasesAndPopulate (data) { * Get challenge. * @param {Object} currentUser the user who perform operation * @param {String} id the challenge id + * @param {Boolean} checkIfExists flag to check if challenge exists * @returns {Object} the challenge with given id */ -async function getChallenge (currentUser, id) { +async function getChallenge (currentUser, id, checkIfExists) { const span = await logger.startSpan('ChallengeService.getChallenge') // get challenge from Elasticsearch let challenge @@ -1272,6 +1273,10 @@ async function getChallenge (currentUser, id) { throw e } } + if (checkIfExists) { + return _.pick(challenge, ['id', 'legacyId']) + } + await helper.ensureUserCanViewChallenge(currentUser, challenge) // // FIXME: Temporarily hard coded as the migrad @@ -1318,7 +1323,8 @@ async function getChallenge (currentUser, id) { getChallenge.schema = { currentUser: Joi.any(), - id: Joi.id() + id: Joi.id(), + checkIfExists: Joi.boolean() } /**