Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/controllers/ChallengeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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)
}

Expand Down Expand Up @@ -116,6 +116,5 @@ module.exports = {
partiallyUpdateChallenge,
deleteChallenge,
getChallengeStatistics,
sendNotifications,
getChallengeStatistics
sendNotifications
}
9 changes: 7 additions & 2 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1221,9 +1221,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) {
// get challenge from Elasticsearch
let challenge
// logger.warn(JSON.stringify({
Expand All @@ -1244,6 +1245,9 @@ 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
Expand Down Expand Up @@ -1288,7 +1292,8 @@ async function getChallenge (currentUser, id) {

getChallenge.schema = {
currentUser: Joi.any(),
id: Joi.id()
id: Joi.id(),
checkIfExists: Joi.boolean()
}

/**
Expand Down