Skip to content

Commit

Permalink
[TECH] Retirer les imports directs en dehors des repositories autoris…
Browse files Browse the repository at this point in the history
…és aux fichiers "datasources/learning-content/*" (PIX-15474)

 #10674
  • Loading branch information
pix-service-auto-merge authored Nov 29, 2024
2 parents 25b0026 + 4577d23 commit 8938b33
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 50 deletions.
4 changes: 2 additions & 2 deletions api/db/seeds/data/common/tooling/learning-content.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import _ from 'lodash';

import { skillDatasource } from '../../../../../src/shared/infrastructure/datasources/learning-content/skill-datasource.js';
import * as challengeRepository from '../../../../../src/shared/infrastructure/repositories/challenge-repository.js';
import * as competenceRepository from '../../../../../src/shared/infrastructure/repositories/competence-repository.js';
import * as skillRepository from '../../../../../src/shared/infrastructure/repositories/skill-repository.js';
import { logger } from '../../../../../src/shared/infrastructure/utils/logger.js';

let ALL_COMPETENCES, ALL_ACTIVE_SKILLS, ALL_CHALLENGES, ACTIVE_SKILLS_BY_COMPETENCE, ACTIVE_SKILLS_BY_TUBE;
Expand Down Expand Up @@ -35,7 +35,7 @@ async function getCoreCompetences() {

async function getAllActiveSkills() {
if (!ALL_ACTIVE_SKILLS) {
ALL_ACTIVE_SKILLS = await skillDatasource.findActive();
ALL_ACTIVE_SKILLS = (await skillRepository.list()).filter((skill) => skill.status === 'actif');
}
return ALL_ACTIVE_SKILLS;
}
Expand Down
4 changes: 2 additions & 2 deletions api/lib/infrastructure/repositories/campaign-repository.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { knex } from '../../../db/knex-database-connection.js';
import * as tubeRepository from '../../../lib/infrastructure/repositories/tube-repository.js';
import { CAMPAIGN_FEATURES } from '../../../src/shared/domain/constants.js';
import { NotFoundError } from '../../../src/shared/domain/errors.js';
import { Campaign } from '../../../src/shared/domain/models/Campaign.js';
import { tubeDatasource } from '../../../src/shared/infrastructure/datasources/learning-content/tube-datasource.js';
import * as skillRepository from '../../../src/shared/infrastructure/repositories/skill-repository.js';
import { DomainTransaction } from '../DomainTransaction.js';

Expand Down Expand Up @@ -127,7 +127,7 @@ const findTubes = async function ({ campaignId }) {

const findAllSkills = async function ({ campaignId }) {
const tubeIds = await findTubes({ campaignId });
const tubes = await tubeDatasource.findByRecordIds(tubeIds);
const tubes = await tubeRepository.findByRecordIds(tubeIds);
const skillIds = tubes.flatMap((tube) => tube.skillIds);
return skillRepository.findByRecordIds(skillIds);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import _ from 'lodash';

// TODO modifier les dépendances avec datasource en meme temps que la PR de lecture, pour des considérations de perf
import { Answer } from '../../../src/evaluation/domain/models/Answer.js';
import { Challenge } from '../../../src/shared/domain/models/Challenge.js';
import { Correction } from '../../../src/shared/domain/models/Correction.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import _ from 'lodash';
import yargs from 'yargs';

import { disconnect, knex } from '../../db/knex-database-connection.js';
import { competenceDatasource } from '../../src/shared/infrastructure/datasources/learning-content/competence-datasource.js';
import * as competenceRepository from '../../src/shared/infrastructure/repositories/competence-repository.js';

const CERTIF_ERROR_RATE = 0.05;
const CERTIF_REJECTED_RATE = 0.15;
Expand Down Expand Up @@ -79,7 +79,7 @@ async function _do({ organizationId, certificationCenterId }) {
await _createCertificationResultsInError({ assessmentIds: errorAssessmentIds, transaction });
console.log('\tOK');

const competences = await competenceDatasource.list();
const competences = await competenceRepository.list();
const pixCompetences = competences.filter((competence) => competence.origin === 'Pix');
const rejectedCount = parseInt(allAssessmentIds.length * CERTIF_REJECTED_RATE);
const rejectedAssessmentIds = _.sampleSize(allAssessmentIds, rejectedCount);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import _ from 'lodash';

import { LOCALE } from '../../../../shared/domain/constants.js';

const { FRENCH_SPOKEN } = LOCALE;
import { knex } from '../../../../../db/knex-database-connection.js';
import * as knowledgeElementRepository from '../../../../../lib/infrastructure/repositories/knowledge-element-repository.js';
import { NotFoundError } from '../../../../../src/shared/domain/errors.js';
import * as tubeRepository from '../../../../../lib/infrastructure/repositories/tube-repository.js';
import * as areaRepository from '../../../../../src/shared/infrastructure/repositories/area-repository.js';
import * as competenceRepository from '../../../../../src/shared/infrastructure/repositories/competence-repository.js';
import * as skillRepository from '../../../../../src/shared/infrastructure/repositories/skill-repository.js';
import { NotFoundError } from '../../../../shared/domain/errors.js';
import {
CertifiedArea,
CertifiedCompetence,
CertifiedProfile,
CertifiedSkill,
CertifiedTube,
} from '../../../../../src/shared/domain/read-models/CertifiedProfile.js';
import {
areaDatasource,
competenceDatasource,
skillDatasource,
tubeDatasource,
} from '../../../../../src/shared/infrastructure/datasources/learning-content/index.js';
} from '../../../../shared/domain/read-models/CertifiedProfile.js';

const get = async function (certificationCourseId) {
const certificationDatas = await knex
Expand Down Expand Up @@ -63,56 +64,60 @@ const get = async function (certificationCourseId) {
export { get };

async function _createCertifiedSkills(skillIds, askedSkillIds) {
const learningContentSkills = await skillDatasource.findByRecordIds(skillIds);
return learningContentSkills.map((learningContentSkill) => {
const skills = await skillRepository.findByRecordIds(skillIds);
return skills.map((skill) => {
return new CertifiedSkill({
id: learningContentSkill.id,
name: learningContentSkill.name,
hasBeenAskedInCertif: askedSkillIds.includes(learningContentSkill.id),
tubeId: learningContentSkill.tubeId,
difficulty: learningContentSkill.level,
id: skill.id,
name: skill.name,
hasBeenAskedInCertif: askedSkillIds.includes(skill.id),
tubeId: skill.tubeId,
difficulty: skill.difficulty,
});
});
}

async function _createCertifiedTubes(certifiedSkills) {
const certifiedSkillsByTube = _.groupBy(certifiedSkills, 'tubeId');
const learningContentTubes = await tubeDatasource.findByRecordIds(Object.keys(certifiedSkillsByTube));
return learningContentTubes.map((learningContentTube) => {
const name = learningContentTube.practicalTitle_i18n.fr;
const tubes = await tubeRepository.findByRecordIds(Object.keys(certifiedSkillsByTube), FRENCH_SPOKEN);
return tubes.map((tube) => {
const name = tube.practicalTitle;
return new CertifiedTube({
id: learningContentTube.id,
id: tube.id,
name,
competenceId: learningContentTube.competenceId,
competenceId: tube.competenceId,
});
});
}

async function _createCertifiedCompetences(certifiedTubes) {
const certifiedTubesByCompetence = _.groupBy(certifiedTubes, 'competenceId');
const learningContentCompetences = await competenceDatasource.findByRecordIds(
Object.keys(certifiedTubesByCompetence),
);
return learningContentCompetences.map((learningContentCompetence) => {
const name = learningContentCompetence.name_i18n.fr;
const competences = await competenceRepository.findByRecordIds({
competenceIds: Object.keys(certifiedTubesByCompetence),
locale: FRENCH_SPOKEN,
});
return competences.map((competence) => {
const name = competence.name;
return new CertifiedCompetence({
id: learningContentCompetence.id,
id: competence.id,
name,
areaId: learningContentCompetence.areaId,
origin: learningContentCompetence.origin,
areaId: competence.areaId,
origin: competence.origin,
});
});
}

async function _createCertifiedAreas(certifiedCompetences) {
const certifiedCompetencesByArea = _.groupBy(certifiedCompetences, 'areaId');
const learningContentAreas = await areaDatasource.findByRecordIds(Object.keys(certifiedCompetencesByArea));
return learningContentAreas.map((learningContentArea) => {
const name = learningContentArea.title_i18n.fr;
const areas = await areaRepository.findByRecordIds({
areaIds: Object.keys(certifiedCompetencesByArea),
locale: FRENCH_SPOKEN,
});
return areas.map((area) => {
const name = area.title;
return new CertifiedArea({
id: learningContentArea.id,
id: area.id,
name,
color: learningContentArea.color,
color: area.color,
});
});
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as certifiedProfileRepository from '../../../../../../src/certification/results/infrastructure/repositories/certified-profile-repository.js';
import { NotFoundError } from '../../../../../../src/shared/domain/errors.js';
import { KnowledgeElement } from '../../../../../../src/shared/domain/models/KnowledgeElement.js';
import { KnowledgeElement } from '../../../../../../src/shared/domain/models/index.js';
import { CertifiedProfile } from '../../../../../../src/shared/domain/read-models/CertifiedProfile.js';
import { catchErr, databaseBuilder, domainBuilder, expect } from '../../../../../test-helper.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { CAMPAIGN_FEATURES } from '../../../../src/shared/domain/constants.js';
import { NotFoundError } from '../../../../src/shared/domain/errors.js';
import { Campaign } from '../../../../src/shared/domain/models/Campaign.js';
import { databaseBuilder, domainBuilder, expect, mockLearningContent } from '../../../test-helper.js';
import { buildArea } from '../../../tooling/domain-builder/factory/build-area.js';
import { buildCompetence } from '../../../tooling/domain-builder/factory/build-competence.js';
import { buildFramework } from '../../../tooling/domain-builder/factory/build-framework.js';
import { buildSkill } from '../../../tooling/domain-builder/factory/build-skill.js';
import { buildThematic } from '../../../tooling/domain-builder/factory/build-thematic.js';
import { buildTube } from '../../../tooling/domain-builder/factory/build-tube.js';
import { buildLearningContent } from '../../../tooling/learning-content-builder/build-learning-content.js';
import {
buildArea,
buildCompetence,
buildFramework,
buildSkill,
buildThematic,
buildTube,
} from '../../../tooling/domain-builder/factory/index.js';
import { buildLearningContent } from '../../../tooling/learning-content-builder/index.js';

describe('Integration | Repository | Campaign', function () {
describe('#areKnowledgeElementsResettable', function () {
Expand Down
4 changes: 1 addition & 3 deletions api/tests/tooling/learning-content-builder/build-skill.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as skillDatasource from '../../../src/shared/infrastructure/datasources/learning-content/skill-datasource.js';

const buildSkill = function buildSkill({
id = 'recSK123',
name = '@sau6',
Expand All @@ -10,7 +8,7 @@ const buildSkill = function buildSkill({
tubeId = 'recTUB123',
version = 1,
level = 6,
status = skillDatasource.ACTIVE_STATUS,
status = 'actif',
} = {}) {
return {
id,
Expand Down

0 comments on commit 8938b33

Please sign in to comment.