From bfca7b5d334bde065fa3c25155dbd41c4f2d8f68 Mon Sep 17 00:00:00 2001 From: Marios Kranitsas Date: Fri, 26 Aug 2022 11:59:48 +0300 Subject: [PATCH] support a checkIfExists query parameter --- src/controllers/ChallengeController.js | 5 ++--- src/services/ChallengeService.js | 9 +++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/controllers/ChallengeController.js b/src/controllers/ChallengeController.js index b1d8e133..3fe6ee5f 100644 --- a/src/controllers/ChallengeController.js +++ b/src/controllers/ChallengeController.js @@ -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) } @@ -116,6 +116,5 @@ module.exports = { partiallyUpdateChallenge, deleteChallenge, getChallengeStatistics, - sendNotifications, - getChallengeStatistics + sendNotifications } diff --git a/src/services/ChallengeService.js b/src/services/ChallengeService.js index cd1939d1..ed15a9a7 100644 --- a/src/services/ChallengeService.js +++ b/src/services/ChallengeService.js @@ -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({ @@ -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 @@ -1288,7 +1292,8 @@ async function getChallenge (currentUser, id) { getChallenge.schema = { currentUser: Joi.any(), - id: Joi.id() + id: Joi.id(), + checkIfExists: Joi.boolean() } /**