From 37b33dbbf0f23a91107d8180d5037ec4059c6345 Mon Sep 17 00:00:00 2001 From: Bastien Seree Date: Thu, 19 Sep 2024 10:41:37 +0200 Subject: [PATCH] Cyberleague: [#134] Add bellwether_count computed field to score schema --- backend/web/server/plugins/cyberleague/functions.js | 3 ++- backend/web/server/plugins/cyberleague/schemas/ScoreSchema.js | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/web/server/plugins/cyberleague/functions.js b/backend/web/server/plugins/cyberleague/functions.js index 06b0b127c..f1fd9b26c 100644 --- a/backend/web/server/plugins/cyberleague/functions.js +++ b/backend/web/server/plugins/cyberleague/functions.js @@ -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}) @@ -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) diff --git a/backend/web/server/plugins/cyberleague/schemas/ScoreSchema.js b/backend/web/server/plugins/cyberleague/schemas/ScoreSchema.js index 5445f5650..59086ab6e 100644 --- a/backend/web/server/plugins/cyberleague/schemas/ScoreSchema.js +++ b/backend/web/server/plugins/cyberleague/schemas/ScoreSchema.js @@ -71,6 +71,10 @@ const ScoreSchema = new Schema({ } }] }, + bellwether_count: { + type: Number, + default: 0 + }, completed: { type: Boolean, required: true,