Skip to content

Commit

Permalink
[TECH] Migrer la route des resultats d'une participation dans son Bou…
Browse files Browse the repository at this point in the history
…nded Context (PIX-15193)

 #10485
  • Loading branch information
pix-service-auto-merge authored Nov 6, 2024
2 parents a438791 + c0a8f97 commit dae1a77
Show file tree
Hide file tree
Showing 19 changed files with 628 additions and 596 deletions.
25 changes: 0 additions & 25 deletions api/lib/application/users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,31 +274,6 @@ const register = async function (server) {
tags: ['api'],
},
},
{
method: 'GET',
path: '/api/users/{userId}/campaigns/{campaignId}/assessment-result',
config: {
validate: {
params: Joi.object({
userId: identifiersType.userId,
campaignId: identifiersType.campaignId,
}),
},
pre: [
{
method: securityPreHandlers.checkRequestedUserIsAuthenticatedUser,
assign: 'requestedUserIsAuthenticatedUser',
},
],
handler: userController.getUserCampaignAssessmentResult,
notes: [
'- **Cette route est restreinte aux utilisateurs authentifiés**\n' +
'- Récupération des résultats d’un parcours pour un utilisateur (**userId**) et pour la campagne d’évaluation donnée (**campaignId**)\n' +
'- L’id demandé doit correspondre à celui de l’utilisateur authentifié',
],
tags: ['api', 'user', 'campaign'],
},
},
{
method: 'GET',
path: '/api/users/{userId}/campaigns/{campaignId}/campaign-participations',
Expand Down
23 changes: 0 additions & 23 deletions api/lib/application/users/user-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { usecases } from '../../domain/usecases/index.js';
import { DomainTransaction } from '../../infrastructure/DomainTransaction.js';
import * as campaignParticipationOverviewSerializer from '../../infrastructure/serializers/jsonapi/campaign-participation-overview-serializer.js';
import * as certificationCenterMembershipSerializer from '../../infrastructure/serializers/jsonapi/certification-center-membership-serializer.js';
import * as participantResultSerializer from '../../infrastructure/serializers/jsonapi/participant-result-serializer.js';
import * as userAnonymizedDetailsForAdminSerializer from '../../infrastructure/serializers/jsonapi/user-anonymized-details-for-admin-serializer.js';
import * as userOrganizationForAdminSerializer from '../../infrastructure/serializers/jsonapi/user-organization-for-admin-serializer.js';

Expand Down Expand Up @@ -110,27 +109,6 @@ const getUserCampaignParticipationToCampaign = function (
.then((campaignParticipation) => dependencies.campaignParticipationSerializer.serialize(campaignParticipation));
};

const getUserCampaignAssessmentResult = async function (
request,
h,
dependencies = {
participantResultSerializer,
requestResponseUtils,
},
) {
const authenticatedUserId = request.auth.credentials.userId;
const campaignId = request.params.campaignId;
const locale = dependencies.requestResponseUtils.extractLocaleFromRequest(request);

const campaignAssessmentResult = await usecases.getUserCampaignAssessmentResult({
userId: authenticatedUserId,
campaignId,
locale,
});

return dependencies.participantResultSerializer.serialize(campaignAssessmentResult);
};

const anonymizeUser = async function (request, h, dependencies = { userAnonymizedDetailsForAdminSerializer }) {
const userToAnonymizeId = request.params.id;
const adminMemberId = request.auth.credentials.userId;
Expand Down Expand Up @@ -217,7 +195,6 @@ const userController = {
findUserOrganizationsForAdmin,
getCampaignParticipationOverviews,
getCampaignParticipations,
getUserCampaignAssessmentResult,
getUserCampaignParticipationToCampaign,
getUserDetailsForAdmin,
reassignAuthenticationMethods,
Expand Down
2 changes: 0 additions & 2 deletions api/lib/domain/usecases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ import * as membershipRepository from '../../infrastructure/repositories/members
import * as organizationLearnerRepository from '../../infrastructure/repositories/organization-learner-repository.js';
import * as organizationMemberIdentityRepository from '../../infrastructure/repositories/organization-member-identity-repository.js';
import * as organizationTagRepository from '../../infrastructure/repositories/organization-tag-repository.js';
import * as participantResultRepository from '../../infrastructure/repositories/participant-result-repository.js';
import { participantResultsSharedRepository } from '../../infrastructure/repositories/participant-results-shared-repository.js';
import * as studentRepository from '../../infrastructure/repositories/student-repository.js';
import * as targetProfileForUpdateRepository from '../../infrastructure/repositories/target-profile-for-update-repository.js';
Expand Down Expand Up @@ -291,7 +290,6 @@ const dependencies = {
organizationRepository,
organizationTagRepository,
organizationValidator,
participantResultRepository,
participantResultsSharedRepository,
passwordGenerator,
passwordValidator,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as campaignAnalysisSerializer from '../infrastructure/serializers/jsona
import * as campaignAssessmentParticipationResultSerializer from '../infrastructure/serializers/jsonapi/campaign-assessment-participation-result-serializer.js';
import * as campaignAssessmentParticipationSerializer from '../infrastructure/serializers/jsonapi/campaign-assessment-participation-serializer.js';
import * as campaignProfileSerializer from '../infrastructure/serializers/jsonapi/campaign-profile-serializer.js';
import * as participantResultSerializer from '../infrastructure/serializers/jsonapi/participant-result-serializer.js';
import * as participationForCampaignManagementSerializer from '../infrastructure/serializers/jsonapi/participation-for-campaign-management-serializer.js';

const findPaginatedParticipationsForCampaignManagement = async function (request) {
Expand Down Expand Up @@ -116,8 +117,30 @@ const getCampaignParticipationsForOrganizationLearner = async function (
return dependencies.availableCampaignParticipationsSerializer.serialize(availableCampaignParticipations);
};

const getUserCampaignAssessmentResult = async function (
request,
_,
dependencies = {
participantResultSerializer,
extractLocaleFromRequest,
},
) {
const authenticatedUserId = request.auth.credentials.userId;
const campaignId = request.params.campaignId;
const locale = dependencies.extractLocaleFromRequest(request);

const campaignAssessmentResult = await usecases.getUserCampaignAssessmentResult({
userId: authenticatedUserId,
campaignId,
locale,
});

return dependencies.participantResultSerializer.serialize(campaignAssessmentResult);
};

const campaignParticipationController = {
findPaginatedParticipationsForCampaignManagement,
getUserCampaignAssessmentResult,
getAnalysis,
getCampaignProfile,
getCampaignAssessmentParticipation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,31 @@ const register = async function (server) {
tags: ['api', 'campaign-participations'],
},
},
{
method: 'GET',
path: '/api/users/{userId}/campaigns/{campaignId}/assessment-result',
config: {
validate: {
params: Joi.object({
userId: identifiersType.userId,
campaignId: identifiersType.campaignId,
}),
},
pre: [
{
method: securityPreHandlers.checkRequestedUserIsAuthenticatedUser,
assign: 'requestedUserIsAuthenticatedUser',
},
],
handler: campaignParticipationController.getUserCampaignAssessmentResult,
notes: [
'- **Cette route est restreinte aux utilisateurs authentifiés**\n' +
'- Récupération des résultats d’un parcours pour un utilisateur (**userId**) et pour la campagne d’évaluation donnée (**campaignId**)\n' +
'- L’id demandé doit correspondre à celui de l’utilisateur authentifié',
],
tags: ['api', 'user', 'campaign'],
},
},
]);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// eslint-disable-next-line @eslint-community/eslint-comments/disable-enable-pair
/* eslint-disable import/no-restricted-paths */
import * as defaultCompareStageAndAcquiredStagesService from '../../../src/evaluation/domain/services/stages/stage-and-stage-acquisition-comparison-service.js';
import * as defaultStageAcquisitionRepository from '../../../src/evaluation/infrastructure/repositories/stage-acquisition-repository.js';
import * as defaultStageRepository from '../../../src/evaluation/infrastructure/repositories/stage-repository.js';
import { NoCampaignParticipationForUserAndCampaign, NotFoundError } from '../../../src/shared/domain/errors.js';
import { CampaignParticipationStatuses } from '../../../src/shared/domain/models/index.js';
import * as defaultParticipantResultRepository from '../../infrastructure/repositories/participant-result-repository.js';
import { NoCampaignParticipationForUserAndCampaign, NotFoundError } from '../../../../shared/domain/errors.js';
import { CampaignParticipationStatuses } from '../../../../shared/domain/models/index.js';

const getUserCampaignAssessmentResult = async function ({
userId,
Expand All @@ -14,10 +8,10 @@ const getUserCampaignAssessmentResult = async function ({
badgeRepository,
knowledgeElementRepository,
badgeForCalculationRepository,
stageRepository = defaultStageRepository,
stageAcquisitionRepository = defaultStageAcquisitionRepository,
participantResultRepository = defaultParticipantResultRepository,
compareStagesAndAcquiredStages = defaultCompareStageAndAcquiredStagesService,
participantResultRepository,
stageRepository,
stageAcquisitionRepository,
compareStagesAndAcquiredStages,
}) {
const { SHARED, TO_SHARE } = CampaignParticipationStatuses;
const campaignParticipationStatus = await participantResultRepository.getCampaignParticipationStatus({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

import * as badgeAcquisitionRepository from '../../../../../lib/infrastructure/repositories/badge-acquisition-repository.js';
import * as badgeForCalculationRepository from '../../../../../lib/infrastructure/repositories/badge-for-calculation-repository.js';
import * as campaignRepository from '../../../../../lib/infrastructure/repositories/campaign-repository.js';
import * as knowledgeElementRepository from '../../../../../lib/infrastructure/repositories/knowledge-element-repository.js';
import * as learningContentRepository from '../../../../../lib/infrastructure/repositories/learning-content-repository.js';
// TODO : use an API for this import
import * as organizationLearnerRepository from '../../../../../lib/infrastructure/repositories/organization-learner-repository.js';
import * as stageCollectionRepository from '../../../../../lib/infrastructure/repositories/user-campaign-results/stage-collection-repository.js';
import * as badgeRepository from '../../../../../src/evaluation/infrastructure/repositories/badge-repository.js';
import * as tutorialRepository from '../../../../devcomp/infrastructure/repositories/tutorial-repository.js';
import * as compareStagesAndAcquiredStages from '../../../../evaluation/domain/services/stages/stage-and-stage-acquisition-comparison-service.js';
import * as competenceEvaluationRepository from '../../../../evaluation/infrastructure/repositories/competence-evaluation-repository.js';
import * as stageAcquisitionRepository from '../../../../evaluation/infrastructure/repositories/stage-acquisition-repository.js';
import * as stageRepository from '../../../../evaluation/infrastructure/repositories/stage-repository.js';
import * as areaRepository from '../../../../shared/infrastructure/repositories/area-repository.js';
import * as assessmentRepository from '../../../../shared/infrastructure/repositories/assessment-repository.js';
import * as competenceRepository from '../../../../shared/infrastructure/repositories/competence-repository.js';
Expand All @@ -20,38 +24,76 @@ import * as campaignAssessmentParticipationRepository from '../../infrastructure
import * as campaignAssessmentParticipationResultRepository from '../../infrastructure/repositories/campaign-assessment-participation-result-repository.js';
import * as campaignParticipationRepository from '../../infrastructure/repositories/campaign-participation-repository.js';
import * as campaignProfileRepository from '../../infrastructure/repositories/campaign-profile-repository.js';
import { repositories as campaignRepositories } from '../../infrastructure/repositories/index.js';
import { repositories as campaignRepositories } from '../../infrastructure/repositories/index.js'; // needed to includes organizationFeatureAPI from another BC
import { participationResultCalculationJobRepository } from '../../infrastructure/repositories/jobs/participation-result-calculation-job-repository.js';
import { participationSharedJobRepository } from '../../infrastructure/repositories/jobs/participation-shared-job-repository.js';
import { participationStartedJobRepository } from '../../infrastructure/repositories/jobs/participation-started-job-repository.js';
import * as participantResultRepository from '../../infrastructure/repositories/participant-result-repository.js';
import * as participationsForCampaignManagementRepository from '../../infrastructure/repositories/participations-for-campaign-management-repository.js';
import * as participationsForUserManagementRepository from '../../infrastructure/repositories/participations-for-user-management-repository.js';
import * as poleEmploiSendingRepository from '../../infrastructure/repositories/pole-emploi-sending-repository.js';
/**
* @typedef { import ('../../../../shared/infrastructure/repositories/area-repository.js')} AreaRepository
* @typedef { import ('../../../../shared/infrastructure/repositories/assessment-repository.js')} AssessmentRepository
* @typedef { import ('../../../../../lib/infrastructure/repositories/badge-acquisition-repository.js')} BadgeAcquisitionRepository
* @typedef { import ('../../../../../lib/infrastructure/repositories/badge-for-calculation-repository.js')} BadgeForCalculationRepository
* @typedef { import ('../../../../../src/evaluation/infrastructure/repositories/badge-repository.js')} BadgeRepository
* @typedef { import ('../../infrastructure/repositories/campaign-analysis-repository.js')} CampaignAnalysisRepository
* @typedef { import ('../../infrastructure/repositories/campaign-assessment-participation-repository.js')} CampaignAssessmentParticipationRepository
* @typedef { import ('../../infrastructure/repositories/campaign-assessment-participation-result-repository.js')} CampaignAssessmentParticipationResultRepository
* @typedef { import ('../../infrastructure/repositories/index.js')} CampaignParticipantRepository
* @typedef { import ('../../infrastructure/repositories/campaign-participation-repository.js')} CampaignParticipationRepository
* @typedef { import ('../../infrastructure/repositories/campaign-profile-repository.js')} CampaignProfileRepository
* @typedef { import ('../../../../../lib/infrastructure/repositories/campaign-repository.js')} CampaignRepository
* @typedef { import ('../../../../evaluation/domain/services/stages/stage-and-stage-acquisition-comparison-service.js')} CompareStagesAndAcquiredStages
* @typedef { import ('../../../../evaluation/infrastructure/repositories/competence-evaluation-repository.js')} CompetenceEvaluationRepository
* @typedef { import ('../../../../shared/infrastructure/repositories/competence-repository.js')} CompetenceRepository
* @typedef { import ('../../../../../lib/infrastructure/repositories/knowledge-element-repository.js')} KnowledgeElementRepository
* @typedef { import ('../../../../../lib/infrastructure/repositories/learning-content-repository.js')} LearningContentRepository
* @typedef { import ('../../../../../lib/infrastructure/repositories/organization-learner-repository.js')} OrganizationLearnerRepository
* @typedef { import ('../../infrastructure/repositories/participant-result-repository.js')} ParticipantResultRepository
* @typedef { import ('../../infrastructure/repositories/jobs/participation-result-calculation-job-repository.js')} ParticipationResultCalculationJobRepository
* @typedef { import ('../../infrastructure/repositories/participations-for-campaign-management-repository.js')} ParticipationsForCampaignManagementRepository
* @typedef { import ('../../infrastructure/repositories/participations-for-user-management-repository.js')} ParticipationsForUserManagementRepository
* @typedef { import ('../../infrastructure/repositories/jobs/participation-shared-job-repository.js')} ParticipationSharedJobRepository
* @typedef { import ('../../infrastructure/repositories/jobs/participation-started-job-repository.js')} ParticipationStartedJobRepository
* @typedef { import ('../../infrastructure/repositories/pole-emploi-sending-repository.js')} PoleEmploiSendingRepository
* @typedef { import ('../../../../evaluation/infrastructure/repositories/stage-acquisition-repository.js')} StageAcquisitionRepository
* @typedef { import ('../../../../../lib/infrastructure/repositories/user-campaign-results/stage-collection-repository.js')} StageCollectionRepository
* @typedef { import ('../../../../evaluation/infrastructure/repositories/stage-repository.js')} StageRepository
* @typedef { import ('../../../../devcomp/infrastructure/repositories/tutorial-repository.js')} TutorialRepository
*/

const dependencies = {
areaRepository,
competenceRepository,
assessmentRepository,
badgeAcquisitionRepository,
badgeForCalculationRepository,
badgeRepository,
campaignAnalysisRepository,
campaignAssessmentParticipationRepository,
campaignAssessmentParticipationResultRepository,
campaignParticipantRepository: campaignRepositories.campaignParticipantRepository,
campaignParticipationRepository,
campaignProfileRepository,
campaignRepository,
compareStagesAndAcquiredStages,
competenceEvaluationRepository,
competenceRepository,
knowledgeElementRepository,
learningContentRepository,
organizationLearnerRepository,
participantResultRepository,
participationResultCalculationJobRepository,
participationsForCampaignManagementRepository,
participationsForUserManagementRepository,
participationSharedJobRepository,
participationStartedJobRepository,
poleEmploiSendingRepository,
stageAcquisitionRepository,
stageCollectionRepository,
stageRepository,
tutorialRepository,
organizationLearnerRepository,
};

const path = dirname(fileURLToPath(import.meta.url));
Expand Down
Loading

0 comments on commit dae1a77

Please sign in to comment.