Skip to content

Commit

Permalink
Cyberleague: Refactor : rename nextQuestionIndex to answerIndex to ma…
Browse files Browse the repository at this point in the history
…ke code more readable
  • Loading branch information
Bastien-Wappizy committed Sep 24, 2024
1 parent 7a1c992 commit 03f5b5c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions backend/web/server/plugins/cyberleague/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ addAction('smartdiet_start_survey', startSurvey)

//value : _id of the answered question
const nextQuestion = async ({ value }, user) => {

const score = await Score.findOne({answers: value}).populate('answers')

const nextQuestionIndex = lodash.findIndex(score.answers, (a)=> idEqual(a._id, value)) + 1
if (nextQuestionIndex == score.answers.length) {
const answerIndex = lodash.findIndex(score.answers, (a)=> idEqual(a._id, value))
if (answerIndex +1 == score.answers.length) {
throw new NotFoundError(`Question ${value} is the last of the quiz`)
}

return score.answers[nextQuestionIndex]
return score.answers[answerIndex +1]
}
//TODO rename action to next_question
addAction('smartdiet_next_question', nextQuestion)

0 comments on commit 03f5b5c

Please sign in to comment.