Skip to content

Commit

Permalink
Cyberleague: [premieroctet#134] Add bellwether_count computed field t…
Browse files Browse the repository at this point in the history
…o score schema
  • Loading branch information
Bastien-Wappizy committed Sep 19, 2024
1 parent f555264 commit 37b33db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backend/web/server/plugins/cyberleague/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ declareVirtualField({model: 'score', field: 'deviation', requires: 'answers.answ
declareVirtualField({model: 'score', field: 'question_count', require: 'answers', instance: 'Number'})
declareEnumField( {model: 'score', field: 'level', enumValues: SCORE_LEVELS})
declareComputedField({model: 'score', field: 'questions_by_category', requires: 'answers.question.question_category._id', getterFn: getQuestionsByCategory})
declareComputedField({model: 'score', field: 'bellwether_count', requires:'is_drafted', getterFn: getterCountFn('score', {'completed': true})})

//Answer declaration
declareEnumField( {model: 'answer', field: 'answer', enumValues: ANSWERS})
Expand Down Expand Up @@ -478,7 +479,7 @@ const postPutData = async ({model, id, params, user}) => {
const answer = await Answer.findById(id)
const score = await Score.findById(answer.score)
const completed = score.answers?.filter(a => !a.answer).length == 0

if (completed) {
const computedScores = await computeScores(score.answers)

Expand Down
4 changes: 4 additions & 0 deletions backend/web/server/plugins/cyberleague/schemas/ScoreSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ const ScoreSchema = new Schema({
}
}]
},
bellwether_count: {
type: Number,
default: 0
},
completed: {
type: Boolean,
required: true,
Expand Down

0 comments on commit 37b33db

Please sign in to comment.