Skip to content

Commit

Permalink
[TECH] Migrer l'injection de certification/shared vers certification/…
Browse files Browse the repository at this point in the history
…session (PIX-11470)

 #8288
  • Loading branch information
pix-service-auto-merge authored Mar 20, 2024
2 parents 1dd0c28 + f37169b commit d58ba0c
Show file tree
Hide file tree
Showing 202 changed files with 1,438 additions and 1,166 deletions.
6 changes: 3 additions & 3 deletions api/lib/application/preHandlers/authorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const verifyCertificationSessionAuthorization = async (
const userId = request.auth.credentials.userId;
const certificationCourseId = request.params.id;

const sessionId = await dependencies.certificationCourseRepository.getSessionId(certificationCourseId);
const sessionId = await dependencies.certificationCourseRepository.getSessionId({ id: certificationCourseId });

return _isAuthorizedToAccessSession({
userId,
Expand All @@ -35,10 +35,10 @@ const authorization = { verifySessionAuthorization, verifyCertificationSessionAu
export { authorization, verifyCertificationSessionAuthorization, verifySessionAuthorization };

async function _isAuthorizedToAccessSession({ userId, sessionId, sessionRepository }) {
const hasMembershipAccess = await sessionRepository.doesUserHaveCertificationCenterMembershipForSession(
const hasMembershipAccess = await sessionRepository.doesUserHaveCertificationCenterMembershipForSession({
userId,
sessionId,
);
});

if (!hasMembershipAccess) {
throw new NotFoundError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const execute = async function ({
certificationCourseId,
dependencies = { certificationCourseRepository, sessionRepository },
}) {
const certificationCourse = await dependencies.certificationCourseRepository.get(certificationCourseId);
return dependencies.sessionRepository.doesUserHaveCertificationCenterMembershipForSession(
const certificationCourse = await dependencies.certificationCourseRepository.get({ id: certificationCourseId });
return dependencies.sessionRepository.doesUserHaveCertificationCenterMembershipForSession({
userId,
certificationCourse.getSessionId(),
);
sessionId: certificationCourse.getSessionId(),
});
};

export { execute };
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as certificationCourseRepository from '../../../src/certification/shared/infrastructure/repositories/certification-course-repository.js';

const execute = async function ({ userId, certificationCourseId, dependencies = { certificationCourseRepository } }) {
const certificationCourse = await dependencies.certificationCourseRepository.get(certificationCourseId);
const certificationCourse = await dependencies.certificationCourseRepository.get({ id: certificationCourseId });
return certificationCourse.doesBelongTo(userId);
};

Expand Down
8 changes: 4 additions & 4 deletions api/lib/domain/events/handle-auto-jury.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bluebird from 'bluebird';

import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js';
import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js';
import { CertificationIssueReportResolutionAttempt } from '../models/CertificationIssueReportResolutionAttempt.js';
import { CertificationIssueReportResolutionStrategies } from '../models/CertificationIssueReportResolutionStrategies.js';
import { CertificationAssessment } from '../models/index.js';
Expand Down Expand Up @@ -177,9 +177,9 @@ async function _autoResolveCertificationIssueReport({
resolutionStrategies,
logger,
}) {
const certificationIssueReports = await certificationIssueReportRepository.findByCertificationCourseId(
certificationCourse.getId(),
);
const certificationIssueReports = await certificationIssueReportRepository.findByCertificationCourseId({
certificationCourseId: certificationCourse.getId(),
});
if (certificationIssueReports.length === 0) {
return null;
}
Expand Down
18 changes: 11 additions & 7 deletions api/lib/domain/events/handle-certification-rescoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { FlashAssessmentAlgorithm } from '../../../src/certification/flash-certi
import { CertificationAssessmentHistory } from '../../../src/certification/scoring/domain/models/CertificationAssessmentHistory.js';
import { CertificationAssessmentScoreV3 } from '../../../src/certification/scoring/domain/models/CertificationAssessmentScoreV3.js';
import { AssessmentResultFactory } from '../../../src/certification/scoring/domain/models/factories/AssessmentResultFactory.js';
import { ABORT_REASONS } from '../../../src/certification/shared/domain/models/CertificationCourse.js';
import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js';
import { config } from '../../../src/shared/config.js';
import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js';
import { CertificationComputeError } from '../errors.js';
import { ABORT_REASONS } from '../models/CertificationCourse.js';
import { CertificationResult } from '../models/CertificationResult.js';
import { CompetenceMark } from '../models/CompetenceMark.js';
import { AssessmentResult } from '../models/index.js';
Expand Down Expand Up @@ -107,7 +107,9 @@ async function _handleV3Certification({
{ certificationCourseId: certificationAssessment.certificationCourseId },
);

const certificationCourse = await certificationCourseRepository.get(certificationAssessment.certificationCourseId);
const certificationCourse = await certificationCourseRepository.get({
id: certificationAssessment.certificationCourseId,
});

const abortReason = certificationCourse.isAbortReasonCandidateRelated()
? ABORT_REASONS.CANDIDATE
Expand Down Expand Up @@ -221,7 +223,9 @@ async function _handleV2Certification({
continueOnError: false,
});
const emitter = _getEmitterFromEvent(event);
const certificationCourse = await certificationCourseRepository.get(certificationAssessment.certificationCourseId);
const certificationCourse = await certificationCourseRepository.get({
id: certificationAssessment.certificationCourseId,
});
const assessmentResult = _createV2AssessmentResult({
event,
emitter,
Expand Down Expand Up @@ -256,14 +260,14 @@ async function _cancelCertificationCourseIfHasNotEnoughNonNeutralizedChallengesT
hasEnoughNonNeutralizedChallengesToBeTrusted,
certificationCourseRepository,
}) {
const certificationCourse = await certificationCourseRepository.get(certificationCourseId);
const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId });
if (hasEnoughNonNeutralizedChallengesToBeTrusted) {
certificationCourse.uncancel();
} else {
certificationCourse.cancel();
}

return certificationCourseRepository.update(certificationCourse);
return certificationCourseRepository.update({ certificationCourse });
}

async function _saveResultAfterCertificationComputeError({
Expand Down Expand Up @@ -417,7 +421,7 @@ async function _cancelCertificationCourseIfV3CertificationLackOfAnswersForTechni
}) {
if (_shouldCancelWhenV3CertificationLacksOfAnswersForTechnicalReason({ allAnswers, certificationCourse })) {
certificationCourse.cancel();
await certificationCourseRepository.update(certificationCourse);
await certificationCourseRepository.update({ certificationCourse });
}
}

Expand Down
20 changes: 12 additions & 8 deletions api/lib/domain/events/handle-certification-scoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { FlashAssessmentAlgorithm } from '../../../src/certification/flash-certi
import { CertificationAssessmentHistory } from '../../../src/certification/scoring/domain/models/CertificationAssessmentHistory.js';
import { CertificationAssessmentScoreV3 } from '../../../src/certification/scoring/domain/models/CertificationAssessmentScoreV3.js';
import { AssessmentResultFactory } from '../../../src/certification/scoring/domain/models/factories/AssessmentResultFactory.js';
import { ABORT_REASONS } from '../../../src/certification/shared/domain/models/CertificationCourse.js';
import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js';
import { config } from '../../../src/shared/config.js';
import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js';
import { CertificationComputeError } from '../errors.js';
import { ABORT_REASONS } from '../models/CertificationCourse.js';
import { CompetenceMark } from '../models/CompetenceMark.js';
import { AssessmentResult } from '../models/index.js';
import { AssessmentCompleted } from './AssessmentCompleted.js';
Expand Down Expand Up @@ -78,7 +78,9 @@ async function _handleV2CertificationScoring({
certificationAssessment,
continueOnError: false,
});
const certificationCourse = await certificationCourseRepository.get(certificationAssessment.certificationCourseId);
const certificationCourse = await certificationCourseRepository.get({
id: certificationAssessment.certificationCourseId,
});
certificationCourse.complete({ now: new Date() });
const assessmentResult = await _createV2AssessmentResult({
certificationAssessment,
Expand Down Expand Up @@ -132,7 +134,7 @@ async function _handleV3CertificationScoring({
certificationCourseId,
});

const certificationCourse = await certificationCourseRepository.get(certificationCourseId);
const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId });

const abortReason = certificationCourse.isAbortReasonCandidateRelated()
? ABORT_REASONS.CANDIDATE
Expand Down Expand Up @@ -228,7 +230,7 @@ async function _saveV2Result({
});

await _saveCompetenceMarks({ certificationAssessmentScore, newAssessmentResult, competenceMarkRepository });
return certificationCourseRepository.update(certificationCourse);
return certificationCourseRepository.update({ certificationCourse });
}

async function _saveV3Result({
Expand All @@ -252,7 +254,7 @@ async function _saveV3Result({
});
return competenceMarkRepository.save(competenceMarkDomain);
});
return certificationCourseRepository.update(certificationCourse);
return certificationCourseRepository.update({ certificationCourse });
}

function _createV2AssessmentResult({ certificationAssessment, certificationAssessmentScore }) {
Expand Down Expand Up @@ -325,7 +327,9 @@ async function _saveResultAfterCertificationComputeError({
certificationCourseRepository,
certificationComputeError,
}) {
const certificationCourse = await certificationCourseRepository.get(certificationAssessment.certificationCourseId);
const certificationCourse = await certificationCourseRepository.get({
id: certificationAssessment.certificationCourseId,
});
const assessmentResult = AssessmentResultFactory.buildAlgoErrorResult({
error: certificationComputeError,
assessmentId: certificationAssessment.id,
Expand All @@ -336,7 +340,7 @@ async function _saveResultAfterCertificationComputeError({
assessmentResult,
});
certificationCourse.complete({ now: new Date() });
return certificationCourseRepository.update(certificationCourse);
return certificationCourseRepository.update({ certificationCourse });
}

handleCertificationScoring.eventTypes = eventTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function handleComplementaryCertificationsScoring({
return;
}

const certificationCourse = await certificationCourseRepository.get(certificationCourseId);
const certificationCourse = await certificationCourseRepository.get({ id: certificationCourseId });
const assessmentResult = await assessmentResultRepository.getByCertificationCourseId({ certificationCourseId });

const {
Expand Down
2 changes: 1 addition & 1 deletion api/lib/domain/events/handle-session-finalized.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function handleSessionFinalized({
juryCertificationSummaries,
});

await finalizedSessionRepository.save(finalizedSession);
await finalizedSessionRepository.save({ finalizedSession });
}

handleSessionFinalized.eventTypes = eventTypes;
Expand Down
2 changes: 1 addition & 1 deletion api/lib/domain/models/CertificationAssessment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import BaseJoi from 'joi';
const Joi = BaseJoi.extend(JoiDate);
import _ from 'lodash';

import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js';
import { AnswerStatus } from '../../../src/shared/domain/models/AnswerStatus.js';
import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js';
import { validateEntity } from '../../../src/shared/domain/validators/entity-validator.js';
import { ChallengeToBeDeneutralizedNotFoundError, ChallengeToBeNeutralizedNotFoundError } from '../errors.js';
import { CertificationAnswerStatusChangeAttempt } from './CertificationAnswerStatusChangeAttempt.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ async function _resolveWithNoSuchQuestion(
questionNumber,
) {
certificationIssueReport.resolveAutomatically(`Aucune question ne correspond au numéro ${questionNumber}`);
await certificationIssueReportRepository.save(certificationIssueReport);
await certificationIssueReportRepository.save({ certificationIssueReport });
return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect();
}

async function _resolveWithQuestionNeutralized(certificationIssueReportRepository, certificationIssueReport) {
certificationIssueReport.resolveAutomatically('Cette question a été neutralisée automatiquement');
await certificationIssueReportRepository.save(certificationIssueReport);
await certificationIssueReportRepository.save({ certificationIssueReport });
return CertificationIssueReportResolutionAttempt.resolvedWithEffect();
}

Expand All @@ -225,37 +225,37 @@ async function _resolveWithNeitherImageNorEmbedInChallenge(
certificationIssueReport.resolveAutomatically(
"Cette question n'a pas été neutralisée car elle ne contient ni image ni application/simulateur",
);
await certificationIssueReportRepository.save(certificationIssueReport);
await certificationIssueReportRepository.save({ certificationIssueReport });
return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect();
}

async function _resolveWithNoAttachmentInChallenge(certificationIssueReportRepository, certificationIssueReport) {
certificationIssueReport.resolveAutomatically(
"Cette question n'a pas été neutralisée car elle ne contient pas de fichier à télécharger",
);
await certificationIssueReportRepository.save(certificationIssueReport);
await certificationIssueReportRepository.save({ certificationIssueReport });
return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect();
}

async function _resolveWithNoFocusedChallenge(certificationIssueReportRepository, certificationIssueReport) {
certificationIssueReport.resolveAutomatically(
"Cette question n'a pas été neutralisée car ce n'est pas une question focus",
);
await certificationIssueReportRepository.save(certificationIssueReport);
await certificationIssueReportRepository.save({ certificationIssueReport });
return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect();
}

async function _resolveWithChallengeNotTimed(certificationIssueReportRepository, certificationIssueReport) {
certificationIssueReport.resolveAutomatically(
"Cette question n'a pas été neutralisée car elle n'est pas chronométrée",
);
await certificationIssueReportRepository.save(certificationIssueReport);
await certificationIssueReportRepository.save({ certificationIssueReport });
return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect();
}

async function _resolveWithAnswerIsCorrect(certificationIssueReportRepository, certificationIssueReport) {
certificationIssueReport.resolveAutomatically("Cette question n'a pas été neutralisée car la réponse est correcte");
await certificationIssueReportRepository.save(certificationIssueReport);
await certificationIssueReportRepository.save({ certificationIssueReport });
return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect();
}

Expand All @@ -266,12 +266,12 @@ async function _resolveWithNeitherSkippedNorFocusedOutAnswer(
certificationIssueReport.resolveAutomatically(
"Cette question n'a pas été neutralisée car la réponse n'a pas été abandonnée ou le focus n'a pas été perdu",
);
await certificationIssueReportRepository.save(certificationIssueReport);
await certificationIssueReportRepository.save({ certificationIssueReport });
return CertificationIssueReportResolutionAttempt.resolvedWithoutEffect();
}

async function _resolveWithAnswerValidated(certificationIssueReportRepository, certificationIssueReport) {
certificationIssueReport.resolveAutomatically('Cette réponse a été acceptée automatiquement');
await certificationIssueReportRepository.save(certificationIssueReport);
await certificationIssueReportRepository.save({ certificationIssueReport });
return CertificationIssueReportResolutionAttempt.resolvedWithEffect();
}
2 changes: 1 addition & 1 deletion api/lib/domain/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FlashAssessmentAlgorithm } from '../../../src/certification/flash-certi
import { CertificationAssessmentScore } from '../../../src/certification/scoring/domain/models/CertificationAssessmentScore.js';
import { CertificationOfficer } from '../../../src/certification/session/domain/models/CertificationOfficer.js';
import { Session } from '../../../src/certification/session/domain/models/Session.js';
import { CertificationCourse } from '../../../src/certification/shared/domain/models/CertificationCourse.js';
import { CertificationIssueReport } from '../../../src/certification/shared/domain/models/CertificationIssueReport.js';
import { CertificationIssueReportCategory } from '../../../src/certification/shared/domain/models/CertificationIssueReportCategory.js';
import { CertificationReport } from '../../../src/certification/shared/domain/models/CertificationReport.js';
Expand Down Expand Up @@ -60,7 +61,6 @@ import { CertificationCenterMembership } from './CertificationCenterMembership.j
import { CertificationChallenge } from './CertificationChallenge.js';
import { CertificationChallengeWithType } from './CertificationChallengeWithType.js';
import { CertificationContract } from './CertificationContract.js';
import { CertificationCourse } from './CertificationCourse.js';
import { CertificationIssueReportResolutionAttempt } from './CertificationIssueReportResolutionAttempt.js';
import { CertificationIssueReportResolutionStrategies } from './CertificationIssueReportResolutionStrategies.js';
import { CertificationResult } from './CertificationResult.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function extractCertificationCandidatesFromCandidatesImportSheet({
mailCheck = mailCheckImplementation,
}) {
const translate = i18n.__;
const certificationCenter = await certificationCenterRepository.getBySessionId(sessionId);
const certificationCenter = await certificationCenterRepository.getBySessionId({ sessionId });
const candidateImportStructs = getTransformationStructsForPixCertifCandidatesImport({
i18n,
complementaryCertifications: certificationCenter.habilitations,
Expand Down
2 changes: 1 addition & 1 deletion api/lib/domain/services/placement-profile-service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bluebird from 'bluebird';
import _ from 'lodash';

import { CertificationVersion } from '../../../src/shared/domain/models/CertificationVersion.js';
import { CertificationVersion } from '../../../src/certification/shared/domain/models/CertificationVersion.js';
import * as assessmentRepository from '../../../src/shared/infrastructure/repositories/assessment-repository.js';
import * as assessmentResultRepository from '../../../src/shared/infrastructure/repositories/assessment-result-repository.js';
import * as competenceRepository from '../../../src/shared/infrastructure/repositories/competence-repository.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _ from 'lodash';

import { CertificationAssessmentScore } from '../../../../src/certification/scoring/domain/models/CertificationAssessmentScore.js';
import { CertificationVersion } from '../../../../src/shared/domain/models/CertificationVersion.js';
import { CertificationVersion } from '../../../../src/certification/shared/domain/models/CertificationVersion.js';
import * as areaRepository from '../../../../src/shared/infrastructure/repositories/area-repository.js';
import { AnswerCollectionForScoring } from '../../models/AnswerCollectionForScoring.js';
import { CertificationContract } from '../../models/CertificationContract.js';
Expand Down
Loading

0 comments on commit d58ba0c

Please sign in to comment.