Skip to content

Commit 03b64ee

Browse files
Merge pull request #521 from topcoder-platform/hotfix/checkIfExist
Hotfix/check if exist
2 parents c4ef25c + bfca7b5 commit 03b64ee

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Diff for: src/controllers/ChallengeController.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async function sendNotifications (req, res) {
6161
* @param {Object} res the response
6262
*/
6363
async function getChallenge (req, res) {
64-
const result = await service.getChallenge(req.authUser, req.params.challengeId)
64+
const result = await service.getChallenge(req.authUser, req.params.challengeId, req.query.checkIfExists)
6565
res.send(result)
6666
}
6767

@@ -116,6 +116,5 @@ module.exports = {
116116
partiallyUpdateChallenge,
117117
deleteChallenge,
118118
getChallengeStatistics,
119-
sendNotifications,
120-
getChallengeStatistics
119+
sendNotifications
121120
}

Diff for: src/services/ChallengeService.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1221,9 +1221,10 @@ async function getPhasesAndPopulate (data) {
12211221
* Get challenge.
12221222
* @param {Object} currentUser the user who perform operation
12231223
* @param {String} id the challenge id
1224+
* @param {Boolean} checkIfExists flag to check if challenge exists
12241225
* @returns {Object} the challenge with given id
12251226
*/
1226-
async function getChallenge (currentUser, id) {
1227+
async function getChallenge (currentUser, id, checkIfExists) {
12271228
// get challenge from Elasticsearch
12281229
let challenge
12291230
// logger.warn(JSON.stringify({
@@ -1244,6 +1245,9 @@ async function getChallenge (currentUser, id) {
12441245
throw e
12451246
}
12461247
}
1248+
if (checkIfExists) {
1249+
return _.pick(challenge, ['id', 'legacyId'])
1250+
}
12471251
await helper.ensureUserCanViewChallenge(currentUser, challenge)
12481252

12491253
// // FIXME: Temporarily hard coded as the migrad
@@ -1288,7 +1292,8 @@ async function getChallenge (currentUser, id) {
12881292

12891293
getChallenge.schema = {
12901294
currentUser: Joi.any(),
1291-
id: Joi.id()
1295+
id: Joi.id(),
1296+
checkIfExists: Joi.boolean()
12921297
}
12931298

12941299
/**

0 commit comments

Comments
 (0)