Skip to content

Commit

Permalink
tech(api): expose directly campaignLearningContent
Browse files Browse the repository at this point in the history
  • Loading branch information
xav-car authored Jan 29, 2025
1 parent f0a0ec9 commit efc388d
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import _ from 'lodash';
import { knex } from '../../../db/knex-database-connection.js';
import * as campaignRepository from '../../../src/prescription/campaign/infrastructure/repositories/campaign-repository.js';
import { NoSkillsInCampaignError, NotFoundError } from '../../../src/shared/domain/errors.js';
import { CampaignLearningContent } from '../../../src/shared/domain/models/CampaignLearningContent.js';
import { LearningContent } from '../../../src/shared/domain/models/LearningContent.js';
import * as areaRepository from '../../../src/shared/infrastructure/repositories/area-repository.js';
import * as competenceRepository from '../../../src/shared/infrastructure/repositories/competence-repository.js';
Expand All @@ -17,7 +18,7 @@ async function findByCampaignId(campaignId, locale) {

const frameworks = await _getLearningContentBySkillIds(skills, locale);

return new LearningContent(frameworks);
return new CampaignLearningContent(frameworks);
}

async function findByTargetProfileId(targetProfileId, locale) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { UserNotAuthorizedToAccessEntityError } from '../../../../shared/domain/errors.js';
import { CampaignLearningContent } from '../../../../shared/domain/models/CampaignLearningContent.js';
import { CampaignParticipationDeletedError } from '../errors.js';

const computeCampaignParticipationAnalysis = async function ({
Expand Down Expand Up @@ -28,8 +27,7 @@ const computeCampaignParticipationAnalysis = async function ({
return null;
}

const learningContent = await learningContentRepository.findByCampaignId(campaignId, locale);
const campaignLearningContent = new CampaignLearningContent(learningContent.frameworks);
const campaignLearningContent = await learningContentRepository.findByCampaignId(campaignId, locale);
const tutorials = await tutorialRepository.list({ locale });

return campaignAnalysisRepository.getCampaignParticipationAnalysis(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { knex } from '../../../../../db/knex-database-connection.js';
import * as learningContentRepository from '../../../../../lib/infrastructure/repositories/learning-content-repository.js';
import { NotFoundError } from '../../../../shared/domain/errors.js';
import { CampaignLearningContent } from '../../../../shared/domain/models/CampaignLearningContent.js';
import * as knowledgeElementRepository from '../../../../shared/infrastructure/repositories/knowledge-element-repository.js';
import { CampaignAssessmentParticipationResult } from '../../domain/models/CampaignAssessmentParticipationResult.js';

const getByCampaignIdAndCampaignParticipationId = async function ({ campaignId, campaignParticipationId, locale }) {
const learningContent = await learningContentRepository.findByCampaignId(campaignId, locale);
const campaignLearningContent = new CampaignLearningContent(learningContent.frameworks);
const campaignLearningContent = await learningContentRepository.findByCampaignId(campaignId, locale);
const result = await _fetchCampaignAssessmentParticipationResultAttributesFromCampaignParticipation(
campaignId,
campaignParticipationId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { UserNotAuthorizedToAccessEntityError } from '../../../../shared/domain/errors.js';
import { CampaignLearningContent } from '../../../../shared/domain/models/CampaignLearningContent.js';

const computeCampaignAnalysis = async function ({
userId,
Expand All @@ -16,8 +15,7 @@ const computeCampaignAnalysis = async function ({
throw new UserNotAuthorizedToAccessEntityError('User does not have access to this campaign');
}

const learningContent = await learningContentRepository.findByCampaignId(campaignId, locale);
const campaignLearningContent = new CampaignLearningContent(learningContent.frameworks);
const campaignLearningContent = await learningContentRepository.findByCampaignId(campaignId, locale);
const tutorials = await tutorialRepository.list({ locale });

return campaignAnalysisRepository.getCampaignAnalysis(campaignId, campaignLearningContent, tutorials);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { UserNotAuthorizedToAccessEntityError } from '../../../../shared/domain/errors.js';
import { CampaignLearningContent } from '../../../../shared/domain/models/CampaignLearningContent.js';

const computeCampaignCollectiveResult = async function ({
userId,
Expand All @@ -15,8 +14,7 @@ const computeCampaignCollectiveResult = async function ({
throw new UserNotAuthorizedToAccessEntityError('User does not have access to this campaign');
}

const learningContent = await learningContentRepository.findByCampaignId(campaignId, locale);
const campaignLearningContent = new CampaignLearningContent(learningContent.frameworks);
const campaignLearningContent = await learningContentRepository.findByCampaignId(campaignId, locale);
return campaignCollectiveResultRepository.getCampaignCollectiveResult(campaignId, campaignLearningContent);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ dayjs.extend(utc);
dayjs.extend(timezone);

import { CampaignTypeError } from '../../../../shared/domain/errors.js';
import { CampaignLearningContent } from '../../../../shared/domain/models/index.js';
import { CampaignAssessmentExport } from '../../infrastructure/serializers/csv/campaign-assessment-export.js';

/**
Expand Down Expand Up @@ -64,7 +63,6 @@ const startWritingCampaignAssessmentResultsToStream = async function ({
const targetProfile = await targetProfileRepository.getByCampaignId(campaign.id);
const learningContent = await learningContentRepository.findByCampaignId(campaign.id, i18n.getLocale());
const stageCollection = await stageCollectionRepository.findStageCollection({ campaignId });
const campaignLearningContent = new CampaignLearningContent(learningContent.frameworks);

const organization = await organizationRepository.get(campaign.organizationId);
const campaignParticipationInfos = await campaignParticipationInfoRepository.findByCampaignId(campaign.id);
Expand All @@ -79,7 +77,7 @@ const startWritingCampaignAssessmentResultsToStream = async function ({
outputStream: writableStream,
organization,
targetProfile,
learningContent: campaignLearningContent,
learningContent,
stageCollection,
campaign,
translate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Unit | UseCase | compute-campaign-participation-analysis', function ()
campaignParticipation.userId = userId;
campaignParticipationRepository.get.withArgs(campaignParticipationId).resolves(campaignParticipation);
campaignRepository.checkIfUserOrganizationHasAccessToCampaign.withArgs(campaignId, userId).resolves(true);
learningContentRepository.findByCampaignId.withArgs(campaignId, locale).resolves(learningContent);
learningContentRepository.findByCampaignId.withArgs(campaignId, locale).resolves(campaignLearningContent);
tutorialRepository.list.withArgs({ locale }).resolves(tutorials);
campaignAnalysisRepository.getCampaignParticipationAnalysis
.withArgs(campaignId, campaignParticipation, campaignLearningContent, tutorials)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Unit | UseCase | compute-campaign-analysis', function () {
const tutorials = Symbol('tutorials');
const campaignAnalysis = Symbol('analysis');
campaignRepository.checkIfUserOrganizationHasAccessToCampaign.withArgs(campaignId, userId).resolves(true);
learningContentRepository.findByCampaignId.withArgs(campaignId, locale).resolves(learningContent);
learningContentRepository.findByCampaignId.withArgs(campaignId, locale).resolves(campaignLearningContent);
tutorialRepository.list.withArgs({ locale }).resolves(tutorials);
campaignAnalysisRepository.getCampaignAnalysis
.withArgs(campaignId, campaignLearningContent, tutorials)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Unit | UseCase | compute-campaign-collective-result', function () {
context('User has access to this result', function () {
beforeEach(function () {
campaignRepository.checkIfUserOrganizationHasAccessToCampaign.withArgs(campaignId, userId).resolves(true);
learningContentRepository.findByCampaignId.withArgs(campaignId, locale).resolves(learningContent);
learningContentRepository.findByCampaignId.withArgs(campaignId, locale).resolves(campaignLearningContent);
});

it('should resolve a CampaignCollectiveResult', async function () {
Expand Down

0 comments on commit efc388d

Please sign in to comment.