Skip to content

Commit

Permalink
Cyberleague: [premieroctet#132] Add virtual question_count to score s…
Browse files Browse the repository at this point in the history
…chema
  • Loading branch information
Bastien-Wappizy committed Sep 16, 2024
1 parent 39fc2ea commit e21fd74
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/web/server/plugins/cyberleague/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ declareVirtualField({model: 'expertiseSet', field: 'display_categories', require
//Score declarations
declareVirtualField({model: 'score', field: 'deviation', requires: 'answers.answer', instance: 'Number'})
declareVirtualField({model: 'score', field: 'is_drafted', requires: 'answers.answer', instance: 'Boolean'})
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})

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 @@ -83,6 +83,10 @@ ScoreSchema.virtual('is_drafted', DUMMY_REF).get(function() {
return this?.answers?.filter(a => !a.answer).length == 0
})

ScoreSchema.virtual('question_count',DUMMY_REF).get(function() {
return this.answers?.length || 0
})

/* eslint-enable prefer-arrow-callback */

module.exports = ScoreSchema

0 comments on commit e21fd74

Please sign in to comment.