Skip to content

Commit

Permalink
[TECH] ♻️ Déplacement des éléments de CertificationCourse vers le c…
Browse files Browse the repository at this point in the history
…ontexte `src/certification/evaluation`

 #10404
  • Loading branch information
pix-service-auto-merge authored Nov 21, 2024
2 parents ffc6fd1 + e94ed28 commit f681713
Show file tree
Hide file tree
Showing 33 changed files with 272 additions and 224 deletions.
2 changes: 1 addition & 1 deletion api/lib/domain/usecases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as complementaryCertificationRepository from '../../../src/certificatio
import * as sessionCodeService from '../../../src/certification/enrolment/domain/services/session-code-service.js';
import { getCenterForAdmin } from '../../../src/certification/enrolment/domain/usecases/get-center-for-admin.js';
import * as centerRepository from '../../../src/certification/enrolment/infrastructure/repositories/center-repository.js';
import * as certificationCandidateRepository from '../../../src/certification/enrolment/infrastructure/repositories/certification-candidate-repository.js';
import * as certificationCpfCityRepository from '../../../src/certification/enrolment/infrastructure/repositories/certification-cpf-city-repository.js';
import * as sessionEnrolmentRepository from '../../../src/certification/enrolment/infrastructure/repositories/session-repository.js';
import * as certificationEvaluationCandidateRepository from '../../../src/certification/evaluation/infrastructure/repositories/certification-candidate-repository.js';
Expand All @@ -23,6 +22,7 @@ import * as supervisorAccessRepository from '../../../src/certification/session-
import * as certificationBadgesService from '../../../src/certification/shared/domain/services/certification-badges-service.js';
import * as scoringCertificationService from '../../../src/certification/shared/domain/services/scoring-certification-service.js';
import * as certificationAssessmentRepository from '../../../src/certification/shared/infrastructure/repositories/certification-assessment-repository.js';
import * as certificationCandidateRepository from '../../../src/certification/shared/infrastructure/repositories/certification-candidate-repository.js';
import * as certificationCenterRepository from '../../../src/certification/shared/infrastructure/repositories/certification-center-repository.js';
import * as certificationChallengeLiveAlertRepository from '../../../src/certification/shared/infrastructure/repositories/certification-challenge-live-alert-repository.js';
import * as certificationChallengeRepository from '../../../src/certification/shared/infrastructure/repositories/certification-challenge-repository.js';
Expand Down
2 changes: 0 additions & 2 deletions api/lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as campaignParticipations from './application/campaign-participations/i
import * as certificationCenterInvitations from './application/certification-center-invitations/index.js';
import * as certificationCenterMemberships from './application/certification-center-memberships/index.js';
import * as certificationCenters from './application/certification-centers/index.js';
import * as certificationCourses from './application/certification-courses/index.js';
import * as certificationPointOfContacts from './application/certification-point-of-contacts/index.js';
import * as certifications from './application/certifications/index.js';
import * as frameworks from './application/frameworks/index.js';
Expand All @@ -24,7 +23,6 @@ const routes = [
certificationCenters,
certificationCenterInvitations,
certificationCenterMemberships,
certificationCourses,
certificationPointOfContacts,
certifications,
healthcheck,
Expand Down
4 changes: 2 additions & 2 deletions api/src/certification/enrolment/domain/usecases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as temporarySessionsStorageForMassImportService from '../services/tempo
* @typedef {import('../../infrastructure/repositories/index.js').ComplementaryCertificationRepository} ComplementaryCertificationRepository
* @typedef {import('../../infrastructure/repositories/index.js').ComplementaryCertificationBadgeWithOffsetVersionRepository} ComplementaryCertificationBadgeWithOffsetVersionRepository
* @typedef {import('../../infrastructure/repositories/index.js').SessionRepository} SessionRepository
* @typedef {import('../../infrastructure/repositories/index.js').CertificationCandidateRepository} CertificationCandidateRepository
* @typedef {import('../../../../shared/infrastructure/repositories/index.js').CertificationCandidateRepository} CertificationCandidateRepository
* @typedef {import('../../../session-management/infrastructure/repositories/index.js').CertificationCandidateForSupervisingRepository} CertificationCandidateForSupervisingRepository
* @typedef {import('../../infrastructure/repositories/index.js').CertificationCpfCityRepository} CertificationCpfCityRepository
* @typedef {import('../../infrastructure/repositories/index.js').CertificationCpfCountryRepository} CertificationCpfCountryRepository
Expand All @@ -32,7 +32,7 @@ import * as temporarySessionsStorageForMassImportService from '../services/tempo
* @typedef {import('../../infrastructure/repositories/index.js').CountryRepository} CountryRepository
* @typedef {import('../../infrastructure/repositories/index.js').ScoCertificationCandidateRepository} ScoCertificationCandidateRepository
* @typedef {import('../../infrastructure/repositories/index.js').OrganizationLearnerRepository} OrganizationLearnerRepository
* @typedef {import('../../infrastructure/repositories/index.js').UserRepository} UserRepository
* @typedef {import('../../../../shared/infrastructure/repositories/index.js').UserRepository} UserRepository
* @typedef {import('../../../shared/domain/validators/session-validator.js')} SessionValidator
* @typedef {import('../../../shared/domain/services/certification-cpf-service.js')} CertificationCpfService
* @typedef {import('../../infrastructure/utils/pdf/attendance-sheet-pdf.js')} AttendanceSheetPdfUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import * as organizationLearnerRepository from '../../../../../lib/infrastructur
import { injectDependencies } from '../../../../shared/infrastructure/utils/dependency-injection.js';
import * as complementaryCertificationApi from '../../../complementary-certification/application/api/complementary-certification-api.js';
import * as sessionManagementRepository from '../../../session-management/infrastructure/repositories/session-repository.js';
import * as certificationCandidateRepository from '../../../shared/infrastructure/repositories/certification-candidate-repository.js';
import * as certificationCenterRepository from '../../../shared/infrastructure/repositories/certification-center-repository.js';
import * as targetProfileHistoryRepository from '../../../shared/infrastructure/repositories/target-profile-history-repository.js';
import * as userRepository from '../../../shared/infrastructure/repositories/user-repository.js';
import * as candidateRepository from './candidate-repository.js';
import * as centerRepository from './center-repository.js';
import * as certificationCandidateRepository from './certification-candidate-repository.js';
import * as certificationCpfCityRepository from './certification-cpf-city-repository.js';
import * as certificationCpfCountryRepository from './certification-cpf-country-repository.js';
import * as complementaryCertificationBadgeWithOffsetVersionRepository from './complementary-certification-badge-with-offset-version-repository.js';
Expand All @@ -18,7 +19,6 @@ import * as pixCertificationRepository from './pix-certification-repository.js';
import * as scoCertificationCandidateRepository from './sco-certification-candidate-repository.js';
import * as sessionForAttendanceSheetRepository from './session-for-attendance-sheet-repository.js';
import * as sessionRepository from './session-repository.js';
import * as userRepository from './user-repository.js';

/**
* Using {@link https://jsdoc.app/tags-type "Closure Compiler's syntax"} to document injected dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { extractLocaleFromRequest } from '../../../src/shared/infrastructure/utils/request-response-utils.js';
import { usecases } from '../../domain/usecases/index.js';
import * as certifiedProfileRepository from '../../infrastructure/repositories/certified-profile-repository.js';
import * as certificationCourseSerializer from '../../infrastructure/serializers/jsonapi/certification-course-serializer.js';
import * as certifiedProfileSerializer from '../../infrastructure/serializers/jsonapi/certified-profile-serializer.js';
import { extractLocaleFromRequest } from '../../../shared/infrastructure/utils/request-response-utils.js';
import { usecases as certificationSharedUsecases } from '../../shared/domain/usecases/index.js';
import { usecases } from '../domain/usecases/index.js';
import * as certificationCourseSerializer from '../infrastructure/serializers/certification-course-serializer.js';

const save = async function (request, h, dependencies = { extractLocaleFromRequest, certificationCourseSerializer }) {
const userId = request.auth.credentials.userId;
Expand All @@ -24,24 +23,13 @@ const save = async function (request, h, dependencies = { extractLocaleFromReque

const get = async function (request, h, dependencies = { certificationCourseSerializer }) {
const certificationCourseId = request.params.id;
const certificationCourse = await usecases.getCertificationCourse({ certificationCourseId });
const certificationCourse = await certificationSharedUsecases.getCertificationCourse({ certificationCourseId });
return dependencies.certificationCourseSerializer.serialize(certificationCourse);
};

const getCertifiedProfile = async function (
request,
h,
dependencies = { certifiedProfileRepository, certifiedProfileSerializer },
) {
const certificationCourseId = request.params.id;
const certifiedProfile = await dependencies.certifiedProfileRepository.get(certificationCourseId);
return dependencies.certifiedProfileSerializer.serialize(certifiedProfile);
};

const certificationCourseController = {
save,
get,
getCertifiedProfile,
};

export { certificationCourseController };
Original file line number Diff line number Diff line change
@@ -1,43 +1,11 @@
import Joi from 'joi';

import { securityPreHandlers } from '../../../src/shared/application/security-pre-handlers.js';
import { identifiersType } from '../../../src/shared/domain/types/identifiers-type.js';
import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js';
import { identifiersType } from '../../../shared/domain/types/identifiers-type.js';
import { certificationCourseController } from './certification-course-controller.js';

const register = async function (server) {
const adminRoutes = [
{
method: 'GET',
path: '/api/admin/certifications/{id}/certified-profile',
config: {
pre: [
{
method: (request, h) =>
securityPreHandlers.hasAtLeastOneAccessOf([
securityPreHandlers.checkAdminMemberHasRoleSuperAdmin,
securityPreHandlers.checkAdminMemberHasRoleCertif,
securityPreHandlers.checkAdminMemberHasRoleSupport,
securityPreHandlers.checkAdminMemberHasRoleMetier,
])(request, h),
assign: 'hasAuthorizationToAccessAdminScope',
},
],
validate: {
params: Joi.object({
id: identifiersType.certificationCourseId,
}),
},
handler: certificationCourseController.getCertifiedProfile,
tags: ['api'],
notes: [
'Cette route est utilisé par Pix Admin',
'Elle permet de récupérer le profil certifié pour une certification donnée',
],
},
},
];
server.route([
...adminRoutes,
{
method: 'POST',
path: '/api/certification-courses',
Expand Down
19 changes: 17 additions & 2 deletions api/src/certification/evaluation/domain/usecases/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

import * as certificationChallengesService from '../../../../../lib/domain/services/certification-challenges-service.js';
import * as verifyCertificateCodeService from '../../../../../lib/domain/services/verify-certificate-code-service.js';
import { pickChallengeService } from '../../../../evaluation/domain/services/pick-challenge-service.js';
import * as languageService from '../../../../shared/domain/services/language-service.js';
import * as placementProfileService from '../../../../shared/domain/services/placement-profile-service.js';
import { injectDependencies } from '../../../../shared/infrastructure/utils/dependency-injection.js';
import { importNamedExportsFromDirectory } from '../../../../shared/infrastructure/utils/import-named-exports-from-directory.js';
import * as flashAlgorithmService from '../../../flash-certification/domain/services/algorithm-methods/flash.js';
Expand All @@ -17,28 +21,39 @@ import {
sessionRepositories,
sharedCompetenceMarkRepository,
} from '../../../session-management/infrastructure/repositories/index.js';
import * as certificationBadgesService from '../../../shared/domain/services/certification-badges-service.js';
import * as sharedCertificationCandidateRepository from '../../../shared/infrastructure/repositories/certification-candidate-repository.js';
import * as certificationCenterRepository from '../../../shared/infrastructure/repositories/certification-center-repository.js';
import * as certificationCourseRepository from '../../../shared/infrastructure/repositories/certification-course-repository.js';
import * as userRepository from '../../../shared/infrastructure/repositories/user-repository.js';
import * as certificationCandidateRepository from '../../infrastructure/repositories/certification-candidate-repository.js';
import * as certificationCompanionAlertRepository from '../../infrastructure/repositories/certification-companion-alert-repository.js';

/**
* @typedef {certificationCompanionAlertRepository} CertificationCompanionAlertRepository
*/

const dependencies = {
...sessionRepositories,
certificationCandidateRepository,
assessmentRepository,
sharedCertificationCandidateRepository,
verifyCertificateCodeService,
assessmentResultRepository,
answerRepository,
sharedCompetenceMarkRepository,
challengeRepository,
userRepository,
competenceMarkRepository,
certificationChallengesService,
cpfExportRepository,
certificationChallengeRepository,
flashAlgorithmConfigurationRepository,
flashAlgorithmService,
languageService,
certificationBadgesService,
pickChallengeService,
placementProfileService,
certificationCenterRepository,
certificationCandidateRepository,
certificationCompanionAlertRepository,
certificationCourseRepository,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@
* @typedef {import('./index.js').AssessmentRepository} AssessmentRepository
* @typedef {import('../../../src/shared/domain/models/CertificationCandidate.js').CertificationCandidate} CertificationCandidate
*/
import { SessionNotAccessible } from '../../../src/certification/session-management/domain/errors.js';
import { ComplementaryCertificationCourse } from '../../../src/certification/session-management/domain/models/ComplementaryCertificationCourse.js';
import { AlgorithmEngineVersion } from '../../../src/certification/shared/domain/models/AlgorithmEngineVersion.js';
import { CertificationCourse } from '../../../src/certification/shared/domain/models/CertificationCourse.js';
import { SessionVersion } from '../../../src/certification/shared/domain/models/SessionVersion.js';
import { config } from '../../../src/shared/config.js';
import { LanguageNotSupportedError } from '../../../src/shared/domain/errors.js';
import { DomainTransaction } from '../../../../../lib/infrastructure/DomainTransaction.js';
import { config } from '../../../../shared/config.js';
import { LanguageNotSupportedError } from '../../../../shared/domain/errors.js';
import {
CandidateNotAuthorizedToJoinSessionError,
CandidateNotAuthorizedToResumeCertificationTestError,
NotFoundError,
UnexpectedUserAccountError,
} from '../../../src/shared/domain/errors.js';
import { Assessment } from '../../../src/shared/domain/models/Assessment.js';
import { DomainTransaction } from '../../infrastructure/DomainTransaction.js';
} from '../../../../shared/domain/errors.js';
import { Assessment } from '../../../../shared/domain/models/Assessment.js';
import { SessionNotAccessible } from '../../../session-management/domain/errors.js';
import { ComplementaryCertificationCourse } from '../../../session-management/domain/models/ComplementaryCertificationCourse.js';
import { AlgorithmEngineVersion } from '../../../shared/domain/models/AlgorithmEngineVersion.js';
import { CertificationCourse } from '../../../shared/domain/models/CertificationCourse.js';
import { SessionVersion } from '../../../shared/domain/models/SessionVersion.js';

const { features } = config;

/**
* @param {Object} params
* @param {SessionRepository} params.sessionRepository
* @param {AssessmentRepository} params.assessmentRepository
* @param {CertificationCandidateRepository} params.certificationCandidateRepository
* @param {CertificationCandidateRepository} params.sharedCertificationCandidateRepository
* @param {CertificationCourseRepository} params.certificationCourseRepository
* @param {UserRepository} params.userRepository
* @param {PlacementProfileService} params.placementProfileService
Expand All @@ -48,7 +48,7 @@ const retrieveLastOrCreateCertificationCourse = async function ({
userId,
locale,
assessmentRepository,
certificationCandidateRepository,
sharedCertificationCandidateRepository,
certificationCourseRepository,
sessionRepository,
certificationCenterRepository,
Expand All @@ -64,7 +64,7 @@ const retrieveLastOrCreateCertificationCourse = async function ({
_validateSessionAccess(session, accessCode);
_validateSessionIsActive(session);

const certificationCandidate = await certificationCandidateRepository.getBySessionIdAndUserId({
const certificationCandidate = await sharedCertificationCandidateRepository.getBySessionIdAndUserId({
userId,
sessionId,
});
Expand All @@ -81,7 +81,7 @@ const retrieveLastOrCreateCertificationCourse = async function ({

await _blockCandidateFromRestartingWithoutExplicitValidation(
certificationCandidate,
certificationCandidateRepository,
sharedCertificationCandidateRepository,
);

if (existingCertificationCourse) {
Expand Down Expand Up @@ -164,10 +164,10 @@ function _validateCandidateIsAuthorizedToStart(certificationCandidate, existingC

async function _blockCandidateFromRestartingWithoutExplicitValidation(
certificationCandidate,
certificationCandidateRepository,
sharedCertificationCandidateRepository,
) {
certificationCandidate.authorizedToStart = false;
await certificationCandidateRepository.update(certificationCandidate);
await sharedCertificationCandidateRepository.update(certificationCandidate);
}

/**
Expand Down Expand Up @@ -200,7 +200,7 @@ async function _startNewCertification({
}) {
let lang;
if (SessionVersion.isV3(session.version)) {
const user = await userRepository.get(userId);
const user = await userRepository.get({ id: userId });
const isUserLanguageValid = _validateUserLanguage(languageService, user.lang);

if (!isUserLanguageValid) {
Expand Down
3 changes: 2 additions & 1 deletion api/src/certification/evaluation/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as companionAlert from '../evaluation/application/companion-alert-route.js';
import * as certificationCourseRoutes from './application/certification-course-route.js';

const certificationEvaluationRoutes = [companionAlert];
const certificationEvaluationRoutes = [companionAlert, certificationCourseRoutes];

export { certificationEvaluationRoutes };
Loading

0 comments on commit f681713

Please sign in to comment.