diff --git a/backend/web/server/plugins/cyberleague/functions.js b/backend/web/server/plugins/cyberleague/functions.js index 6ec0df68f5..2f5ee7ada9 100644 --- a/backend/web/server/plugins/cyberleague/functions.js +++ b/backend/web/server/plugins/cyberleague/functions.js @@ -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}) diff --git a/backend/web/server/plugins/cyberleague/schemas/ScoreSchema.js b/backend/web/server/plugins/cyberleague/schemas/ScoreSchema.js index 42d8835421..533824e43c 100644 --- a/backend/web/server/plugins/cyberleague/schemas/ScoreSchema.js +++ b/backend/web/server/plugins/cyberleague/schemas/ScoreSchema.js @@ -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 \ No newline at end of file