From 5fa42d05547325d1a03db1ca482831134c4a70d3 Mon Sep 17 00:00:00 2001 From: alicegoarnisson Date: Wed, 29 Jan 2025 09:33:27 +0100 Subject: [PATCH] chore(orga): moved every method in parent component --- .../domain/models/CampaignLearningContent.js | 75 ------------------- .../shared/domain/models/LearningContent.js | 74 ++++++++++++++++++ 2 files changed, 74 insertions(+), 75 deletions(-) diff --git a/api/src/shared/domain/models/CampaignLearningContent.js b/api/src/shared/domain/models/CampaignLearningContent.js index 7c70767f1ac..db491c8bcd0 100644 --- a/api/src/shared/domain/models/CampaignLearningContent.js +++ b/api/src/shared/domain/models/CampaignLearningContent.js @@ -1,5 +1,3 @@ -import _ from 'lodash'; - import { LearningContent } from './LearningContent.js'; class CampaignLearningContent extends LearningContent { @@ -14,79 +12,6 @@ class CampaignLearningContent extends LearningContent { get competences() { return super.competences.sort((a, b) => a.index.localeCompare(b.index)); } - - get maxSkillDifficulty() { - const skillMaxDifficulty = _.maxBy(this.skills, 'difficulty'); - return skillMaxDifficulty ? skillMaxDifficulty.difficulty : null; - } - - get tubeIds() { - return this.tubes.map((tube) => tube.id); - } - - getValidatedKnowledgeElementsGroupedByTube(knowledgeElements) { - return this._filterTargetedKnowledgeElementAndGroupByTube( - knowledgeElements, - (knowledgeElement) => knowledgeElement.isValidated, - ); - } - - getKnowledgeElementsGroupedByCompetence(knowledgeElements) { - return this._filterTargetedKnowledgeElementAndGroupByCompetence(knowledgeElements); - } - - countValidatedTargetedKnowledgeElementsByCompetence(knowledgeElements) { - const validatedGroupedByCompetence = this._filterTargetedKnowledgeElementAndGroupByCompetence( - knowledgeElements, - (knowledgeElement) => knowledgeElement.isValidated, - ); - return _.mapValues(validatedGroupedByCompetence, 'length'); - } - - get skillNames() { - return this.skills.map((skill) => skill.name); - } - - _getTubeIdOfSkill(skillId) { - const skillTube = this.tubes.find((tube) => tube.hasSkill(skillId)); - - return skillTube ? skillTube.id : null; - } - - _filterTargetedKnowledgeElementAndGroupByTube(knowledgeElements, knowledgeElementFilter = () => true) { - const knowledgeElementsGroupedByTube = {}; - for (const tubeId of this.tubeIds) { - knowledgeElementsGroupedByTube[tubeId] = []; - } - for (const knowledgeElement of knowledgeElements) { - const tubeId = this._getTubeIdOfSkill(knowledgeElement.skillId); - if (tubeId && knowledgeElementFilter(knowledgeElement)) { - knowledgeElementsGroupedByTube[tubeId].push(knowledgeElement); - } - } - - return knowledgeElementsGroupedByTube; - } - - _filterTargetedKnowledgeElementAndGroupByCompetence(knowledgeElements, knowledgeElementFilter = () => true) { - const knowledgeElementsGroupedByCompetence = {}; - for (const competence of this.competences) { - knowledgeElementsGroupedByCompetence[competence.id] = []; - } - for (const knowledgeElement of knowledgeElements) { - const competenceId = this.findCompetenceIdOfSkill(knowledgeElement.skillId); - if (competenceId && knowledgeElementFilter(knowledgeElement)) { - knowledgeElementsGroupedByCompetence[competenceId].push(knowledgeElement); - } - } - - return knowledgeElementsGroupedByCompetence; - } - - findAreaOfCompetence(competence) { - const area = this.findArea(competence.areaId); - return area || null; - } } export { CampaignLearningContent }; diff --git a/api/src/shared/domain/models/LearningContent.js b/api/src/shared/domain/models/LearningContent.js index 8b92043ac2f..a80f090b60e 100644 --- a/api/src/shared/domain/models/LearningContent.js +++ b/api/src/shared/domain/models/LearningContent.js @@ -1,3 +1,5 @@ +import _ from 'lodash'; + class LearningContent { constructor(frameworks) { this.frameworks = frameworks; @@ -24,6 +26,14 @@ class LearningContent { return this.tubes.flatMap((tube) => tube.skills); } + get skillNames() { + return this.skills.map((skill) => skill.name); + } + + get tubeIds() { + return this.tubes.map((tube) => tube.id); + } + findSkill(skillId) { return this.skills.find((skill) => skill.id === skillId) ?? null; } @@ -40,6 +50,11 @@ class LearningContent { return this.areas.find((area) => area.id === areaId) ?? null; } + findAreaOfCompetence(competence) { + const area = this.findArea(competence.areaId); + return area || null; + } + findFramework(frameworkId) { return this.frameworks.find((framework) => framework.id === frameworkId) ?? null; } @@ -55,6 +70,65 @@ class LearningContent { if (!frameworkId) return ''; return this.findFramework(frameworkId).name; } + getValidatedKnowledgeElementsGroupedByTube(knowledgeElements) { + return this._filterTargetedKnowledgeElementAndGroupByTube( + knowledgeElements, + (knowledgeElement) => knowledgeElement.isValidated, + ); + } + + getKnowledgeElementsGroupedByCompetence(knowledgeElements) { + return this._filterTargetedKnowledgeElementAndGroupByCompetence(knowledgeElements); + } + + countValidatedTargetedKnowledgeElementsByCompetence(knowledgeElements) { + const validatedGroupedByCompetence = this._filterTargetedKnowledgeElementAndGroupByCompetence( + knowledgeElements, + (knowledgeElement) => knowledgeElement.isValidated, + ); + return _.mapValues(validatedGroupedByCompetence, 'length'); + } + + _getTubeIdOfSkill(skillId) { + const skillTube = this.tubes.find((tube) => tube.hasSkill(skillId)); + + return skillTube ? skillTube.id : null; + } + + _filterTargetedKnowledgeElementAndGroupByTube(knowledgeElements, knowledgeElementFilter = () => true) { + const knowledgeElementsGroupedByTube = {}; + for (const tubeId of this.tubeIds) { + knowledgeElementsGroupedByTube[tubeId] = []; + } + for (const knowledgeElement of knowledgeElements) { + const tubeId = this._getTubeIdOfSkill(knowledgeElement.skillId); + if (tubeId && knowledgeElementFilter(knowledgeElement)) { + knowledgeElementsGroupedByTube[tubeId].push(knowledgeElement); + } + } + + return knowledgeElementsGroupedByTube; + } + + _filterTargetedKnowledgeElementAndGroupByCompetence(knowledgeElements, knowledgeElementFilter = () => true) { + const knowledgeElementsGroupedByCompetence = {}; + for (const competence of this.competences) { + knowledgeElementsGroupedByCompetence[competence.id] = []; + } + for (const knowledgeElement of knowledgeElements) { + const competenceId = this.findCompetenceIdOfSkill(knowledgeElement.skillId); + if (competenceId && knowledgeElementFilter(knowledgeElement)) { + knowledgeElementsGroupedByCompetence[competenceId].push(knowledgeElement); + } + } + + return knowledgeElementsGroupedByCompetence; + } + + get maxSkillDifficulty() { + const skillMaxDifficulty = _.maxBy(this.skills, 'difficulty'); + return skillMaxDifficulty ? skillMaxDifficulty.difficulty : null; + } } export { LearningContent };