Skip to content

Commit

Permalink
[TECH] Migrer la route POST /api/admin/certification-centers dans src (
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Nov 18, 2024
2 parents fb78ee1 + 0cbf4d6 commit e4246a1
Show file tree
Hide file tree
Showing 27 changed files with 618 additions and 520 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
import lodash from 'lodash';

import { usecases as certificationConfigurationUsecases } from '../../../src/certification/configuration/domain/usecases/index.js';
import * as certificationCenterForAdminSerializer from '../../../src/organizational-entities/infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.js';
import * as divisionSerializer from '../../../src/prescription/campaign/infrastructure/serializers/jsonapi/division-serializer.js';
import * as certificationCenterMembershipSerializer from '../../../src/shared/infrastructure/serializers/jsonapi/certification-center-membership.serializer.js';
import { usecases as teamUsecases } from '../../../src/team/domain/usecases/index.js';
import { usecases } from '../../domain/usecases/index.js';
import { DomainTransaction } from '../../infrastructure/DomainTransaction.js';
import * as certificationCenterForAdminSerializer from '../../infrastructure/serializers/jsonapi/certification-center-for-admin-serializer.js';
import * as sessionSummarySerializer from '../../infrastructure/serializers/jsonapi/session-summary-serializer.js';
import * as studentCertificationSerializer from '../../infrastructure/serializers/jsonapi/student-certification-serializer.js';

const { map } = lodash;

const create = async function (request) {
const certificationCenter = certificationCenterForAdminSerializer.deserialize(request.payload);
const complementaryCertificationIds = map(request.payload.data.relationships?.habilitations?.data, 'id');
const createdCertificationCenter = await usecases.createCertificationCenter({
certificationCenter,
complementaryCertificationIds,
});
return certificationCenterForAdminSerializer.serialize(createdCertificationCenter);
};

const update = async function (request) {
const certificationCenterId = request.params.id;
const certificationCenterInformation = certificationCenterForAdminSerializer.deserialize(request.payload);
Expand Down Expand Up @@ -140,7 +130,6 @@ const updateReferer = async function (request, h) {
};

const certificationCenterController = {
create,
createCertificationCenterMembershipByEmail,
findCertificationCenterMembershipsByCertificationCenter,
findPaginatedSessionSummaries,
Expand Down
24 changes: 0 additions & 24 deletions api/lib/application/certification-centers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,6 @@ import { certificationCenterController } from './certification-center-controller

const register = async function (server) {
const adminRoutes = [
{
method: 'POST',
path: '/api/admin/certification-centers',
config: {
handler: certificationCenterController.create,
pre: [
{
method: (request, h) =>
securityPreHandlers.hasAtLeastOneAccessOf([
securityPreHandlers.checkAdminMemberHasRoleSuperAdmin,
securityPreHandlers.checkAdminMemberHasRoleCertif,
securityPreHandlers.checkAdminMemberHasRoleSupport,
securityPreHandlers.checkAdminMemberHasRoleMetier,
])(request, h),
assign: 'hasAuthorizationToAccessAdminScope',
},
],
notes: [
"- **Cette route est restreinte aux utilisateurs ayant les droits d'accès**\n" +
'- Création d‘un nouveau centre de certification\n',
],
tags: ['api', 'certification-center'],
},
},
{
method: 'GET',
path: '/api/admin/certification-centers/{id}',
Expand Down
6 changes: 3 additions & 3 deletions api/lib/domain/usecases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ import { resetPasswordDemandRepository } from '../../../src/identity-access-mana
import * as userRepository from '../../../src/identity-access-management/infrastructure/repositories/user.repository.js';
import { userEmailRepository } from '../../../src/identity-access-management/infrastructure/repositories/user-email.repository.js';
import { userToCreateRepository } from '../../../src/identity-access-management/infrastructure/repositories/user-to-create.repository.js';
import * as certificationCenterForAdminRepository from '../../../src/organizational-entities/infrastructure/repositories/certification-center-for-admin.repository.js';
import * as complementaryCertificationHabilitationRepository from '../../../src/organizational-entities/infrastructure/repositories/complementary-certification-habilitation.repository.js';
import * as dataProtectionOfficerRepository from '../../../src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js';
import { organizationForAdminRepository } from '../../../src/organizational-entities/infrastructure/repositories/organization-for-admin.repository.js';
import { tagRepository } from '../../../src/organizational-entities/infrastructure/repositories/tag.repository.js';
import * as campaignManagementRepository from '../../../src/prescription/campaign/infrastructure/repositories/campaign-management-repository.js';
Expand Down Expand Up @@ -128,12 +131,9 @@ import * as campaignParticipationRepository from '../../infrastructure/repositor
import { campaignParticipationResultRepository } from '../../infrastructure/repositories/campaign-participation-result-repository.js';
import * as campaignRepository from '../../infrastructure/repositories/campaign-repository.js';
import * as certifiableProfileForLearningContentRepository from '../../infrastructure/repositories/certifiable-profile-for-learning-content-repository.js';
import * as certificationCenterForAdminRepository from '../../infrastructure/repositories/certification-center-for-admin-repository.js';
import * as certificationPointOfContactRepository from '../../infrastructure/repositories/certification-point-of-contact-repository.js';
import * as certificationRepository from '../../infrastructure/repositories/certification-repository.js';
import * as complementaryCertificationCourseResultRepository from '../../infrastructure/repositories/complementary-certification-course-result-repository.js';
import * as complementaryCertificationHabilitationRepository from '../../infrastructure/repositories/complementary-certification-habilitation-repository.js';
import * as dataProtectionOfficerRepository from '../../infrastructure/repositories/data-protection-officer-repository.js';
import * as flashAssessmentResultRepository from '../../infrastructure/repositories/flash-assessment-result-repository.js';
import * as frameworkRepository from '../../infrastructure/repositories/framework-repository.js';
import { repositories } from '../../infrastructure/repositories/index.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { disconnect } from '../db/knex-database-connection.js';
import { createOrganizationsWithTagsAndTargetProfiles } from '../lib/domain/usecases/create-organizations-with-tags-and-target-profiles.js';
import * as organizationValidator from '../lib/domain/validators/organization-with-tags-and-target-profiles-script.js';
import { DomainTransaction as domainTransaction } from '../lib/infrastructure/DomainTransaction.js';
import * as dataProtectionOfficerRepository from '../lib/infrastructure/repositories/data-protection-officer-repository.js';
import * as organizationTagRepository from '../lib/infrastructure/repositories/organization-tag-repository.js';
import * as targetProfileShareRepository from '../lib/infrastructure/repositories/target-profile-share-repository.js';
import * as dataProtectionOfficerRepository from '../src/organizational-entities/infrastructure/repositories/data-protection-officer.repository.js';
import { tagRepository } from '../src/organizational-entities/infrastructure/repositories/tag.repository.js';
import * as organizationRepository from '../src/shared/infrastructure/repositories/organization-repository.js';
import { temporaryStorage } from '../src/shared/infrastructure/temporary-storage/index.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import { usecases } from '../../domain/usecases/index.js';
import * as certificationCenterSerializer from '../../infrastructure/serializers/jsonapi/certification-center/certification-center.serializer.js';
import * as certificationCenterForAdminSerializer from '../../infrastructure/serializers/jsonapi/certification-center/certification-center-for-admin.serializer.js';

const create = async function (request) {
const certificationCenter = certificationCenterForAdminSerializer.deserialize(request.payload);
const complementaryCertificationIds =
request.payload.data.relationships?.habilitations?.data.map(
(complementaryCertification) => complementaryCertification.id,
) || [];
const createdCertificationCenter = await usecases.createCertificationCenter({
certificationCenter,
complementaryCertificationIds,
});
return certificationCenterForAdminSerializer.serialize(createdCertificationCenter);
};

const findPaginatedFilteredCertificationCenters = async function (
request,
Expand All @@ -15,8 +29,9 @@ const findPaginatedFilteredCertificationCenters = async function (
return dependencies.certificationCenterSerializer.serialize(organizations, pagination);
};

const certificationCenterController = {
const certificationCenterAdminController = {
create,
findPaginatedFilteredCertificationCenters,
};

export { certificationCenterController };
export { certificationCenterAdminController };
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import Joi from 'joi';

import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js';
import { optionalIdentifiersType } from '../../../shared/domain/types/identifiers-type.js';
import { certificationCenterController } from './certification-center.admin.controller.js';
import { certificationCenterAdminController } from './certification-center.admin.controller.js';

const register = async function (server) {
server.route([
{
method: 'GET',
path: '/api/admin/certification-centers',
config: {
handler: certificationCenterController.findPaginatedFilteredCertificationCenters,
handler: certificationCenterAdminController.findPaginatedFilteredCertificationCenters,
pre: [
{
method: (request, h) =>
Expand Down Expand Up @@ -41,7 +41,31 @@ const register = async function (server) {
"- **Cette route est restreinte aux utilisateurs ayant les droits d'accès**\n" +
'- Liste des centres de certification\n',
],
tags: ['api', 'certification-center'],
tags: ['api', 'organizational-entities', 'certification-center'],
},
},
{
method: 'POST',
path: '/api/admin/certification-centers',
config: {
handler: certificationCenterAdminController.create,
pre: [
{
method: (request, h) =>
securityPreHandlers.hasAtLeastOneAccessOf([
securityPreHandlers.checkAdminMemberHasRoleSuperAdmin,
securityPreHandlers.checkAdminMemberHasRoleCertif,
securityPreHandlers.checkAdminMemberHasRoleSupport,
securityPreHandlers.checkAdminMemberHasRoleMetier,
])(request, h),
assign: 'hasAuthorizationToAccessAdminScope',
},
],
notes: [
"- **Cette route est restreinte aux utilisateurs ayant les droits d'accès**\n" +
'- Création d‘un nouveau centre de certification\n',
],
tags: ['api', 'organizational-entities', 'certification-center'],
},
},
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { ComplementaryCertificationHabilitation } from '../../../src/shared/domain/models/ComplementaryCertificationHabilitation.js';
import * as certificationCenterCreationValidator from '../validators/certification-center-creation-validator.js';
import * as certificationCenterCreationValidator from '../../../../lib/domain/validators/certification-center-creation-validator.js';
import { ComplementaryCertificationHabilitation } from '../../../shared/domain/models/ComplementaryCertificationHabilitation.js';

/**
*
* @param{object} params
* @param{CertificationCenter} params.certificationCenter
* @param{string[]} params.complementaryCertificationIds
* @param{ComplementaryCertificationHabilitationRepository} params.complementaryCertificationHabilitationRepository
* @param{CertificationCenterForAdminRepository} params.certificationCenterForAdminRepository
* @param{DataProtectionOfficerRepository} params.dataProtectionOfficerRepository
* @returns {Promise<*>}
*/
const createCertificationCenter = async function ({
certificationCenter,
complementaryCertificationIds,
Expand Down
10 changes: 10 additions & 0 deletions api/src/organizational-entities/domain/usecases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import * as schoolRepository from '../../../school/infrastructure/repositories/s
import { injectDependencies } from '../../../shared/infrastructure/utils/dependency-injection.js';
import { importNamedExportsFromDirectory } from '../../../shared/infrastructure/utils/import-named-exports-from-directory.js';
import * as certificationCenterRepository from '../../infrastructure/repositories/certification-center.repository.js';
import * as certificationCenterForAdminRepository from '../../infrastructure/repositories/certification-center-for-admin.repository.js';
import * as complementaryCertificationHabilitationRepository from '../../infrastructure/repositories/complementary-certification-habilitation.repository.js';
import * as dataProtectionOfficerRepository from '../../infrastructure/repositories/data-protection-officer.repository.js';
import * as organizationFeatureRepository from '../../infrastructure/repositories/organization-feature-repository.js';
import { organizationForAdminRepository } from '../../infrastructure/repositories/organization-for-admin.repository.js';
import { tagRepository } from '../../infrastructure/repositories/tag.repository.js';
Expand All @@ -14,6 +17,9 @@ const path = dirname(fileURLToPath(import.meta.url));

/**
* @typedef {import ('../../infrastructure/repositories/certification-center.repository.js')} CertificationCenterRepository
* @typedef {import ('../../infrastructure/repositories/certification-center-for-admin-repository.js')} CertificationCenterForAdminRepository
* @typedef {import ('../../infrastructure/repositories/complementary-certification-habilitation-repository.js')} ComplementaryCertificationHabilitationRepository
* @typedef {import ('../../infrastructure/repositories/data-protection-officer-repository.js')} DataProtectionOfficerRepository
* @typedef {import ('../../infrastructure/repositories/organization-feature-repository.js')} OrganizationFeatureRepository
* @typedef {import ('../../infrastructure/repositories/organization-for-admin.repository.js')} OrganizationForAdminRepository
* @typedef {import ('../../infrastructure/repositories/tag.repository.js')} TagRepository
Expand All @@ -22,6 +28,9 @@ const path = dirname(fileURLToPath(import.meta.url));

const repositories = {
certificationCenterRepository,
certificationCenterForAdminRepository,
dataProtectionOfficerRepository,
complementaryCertificationHabilitationRepository,
organizationForAdminRepository,
organizationFeatureRepository,
schoolRepository,
Expand All @@ -39,6 +48,7 @@ const usecasesWithoutInjectedDependencies = {
* @typedef OrganizationalEntitiesUsecases
* @property {addOrganizationFeatureInBatch} addOrganizationFeatureInBatch
* @property {attachChildOrganizationToOrganization} attachChildOrganizationToOrganization
* @property {createCertificationCenter} createCertificationCenter
* @property {createTag} createTag
* @property {findPaginatedFilteredCertificationCenters} findPaginatedFilteredCertificationCenters
* @property {getOrganizationDetails} getOrganizationDetails
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CenterForAdmin } from '../../../src/certification/enrolment/domain/models/CenterForAdmin.js';
import { DomainTransaction } from '../DomainTransaction.js';
import { CenterForAdmin } from '../../../certification/enrolment/domain/models/CenterForAdmin.js';
import { DomainTransaction } from '../../../shared/domain/DomainTransaction.js';

const save = async function (certificationCenter) {
const knexConn = DomainTransaction.getConnection();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DomainTransaction } from '../DomainTransaction.js';
import { DomainTransaction } from '../../../shared/domain/DomainTransaction.js';

const COMPLEMENTARY_CERTIFICATION_HABILITATIONS_TABLE_NAME = 'complementary-certification-habilitations';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DataProtectionOfficer } from '../../../src/organizational-entities/domain/models/DataProtectionOfficer.js';
import { DomainTransaction } from '../DomainTransaction.js';
import { DomainTransaction } from '../../../shared/domain/DomainTransaction.js';
import { DataProtectionOfficer } from '../../domain/models/DataProtectionOfficer.js';

const DATA_PROTECTION_OFFICERS_TABLE_NAME = 'data-protection-officers';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import jsonapiSerializer from 'jsonapi-serializer';

const { Serializer } = jsonapiSerializer;

import { CenterForAdmin } from '../../../../src/certification/enrolment/domain/models/CenterForAdmin.js';
import { CenterForAdmin } from '../../../../../certification/enrolment/domain/models/CenterForAdmin.js';

const deserialize = function ({ data }) {
const center = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Joi from 'joi';

import { updateCertificationCenterDataProtectionOfficerInformation } from '../../../lib/domain/usecases/update-certification-center-data-protection-officer-information.js';
import * as dataProtectionOfficerRepository from '../../../lib/infrastructure/repositories/data-protection-officer-repository.js';
import { csvFileParser } from '../../shared/application/scripts/parsers.js';
import { Script } from '../../shared/application/scripts/script.js';
import { ScriptRunner } from '../../shared/application/scripts/script-runner.js';
import * as dataProtectionOfficerRepository from '../infrastructure/repositories/data-protection-officer.repository.js';

const columnsSchemas = [
{ name: 'certificationCenterId', schema: Joi.number() },
Expand Down
Loading

0 comments on commit e4246a1

Please sign in to comment.