Skip to content

support a checkIfExists query parameter #512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2022
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
2 changes: 1 addition & 1 deletion src/controllers/ChallengeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
10 changes: 8 additions & 2 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -1318,7 +1323,8 @@ async function getChallenge (currentUser, id) {

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

/**
Expand Down