Skip to content

Commit

Permalink
chore(orga): moved every method in parent component
Browse files Browse the repository at this point in the history
  • Loading branch information
alicegoarnisson authored Jan 29, 2025
1 parent efc388d commit 5fa42d0
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 75 deletions.
75 changes: 0 additions & 75 deletions api/src/shared/domain/models/CampaignLearningContent.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import _ from 'lodash';

import { LearningContent } from './LearningContent.js';

class CampaignLearningContent extends LearningContent {
Expand All @@ -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 };
74 changes: 74 additions & 0 deletions api/src/shared/domain/models/LearningContent.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import _ from 'lodash';

class LearningContent {
constructor(frameworks) {
this.frameworks = frameworks;
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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 };

0 comments on commit 5fa42d0

Please sign in to comment.