From e21fd74b7eaa6a6ffa24c517860db01152d27ee4 Mon Sep 17 00:00:00 2001 From: Bastien Seree Date: Mon, 16 Sep 2024 09:55:02 +0200 Subject: [PATCH] Cyberleague: [#132] Add virtual question_count to score schema --- backend/web/server/plugins/cyberleague/functions.js | 1 + backend/web/server/plugins/cyberleague/schemas/ScoreSchema.js | 4 ++++ 2 files changed, 5 insertions(+) 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