Skip to content

Commit

Permalink
tech(api): migrate particpant result controller/route to its bounded-…
Browse files Browse the repository at this point in the history
…context
  • Loading branch information
xav-car authored Nov 6, 2024
1 parent b986fd5 commit c0a8f97
Show file tree
Hide file tree
Showing 14 changed files with 553 additions and 558 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
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,6 +1,9 @@
import _ from 'lodash';

import { knex } from '../../../../../db/knex-database-connection.js';
import * as campaignRepository from '../../../../../lib/infrastructure/repositories/campaign-repository.js';
import * as flashAssessmentResultRepository from '../../../../../lib/infrastructure/repositories/flash-assessment-result-repository.js';
import * as knowledgeElementRepository from '../../../../../lib/infrastructure/repositories/knowledge-element-repository.js';
import * as flash from '../../../../certification/flash-certification/domain/services/algorithm-methods/flash.js';
import * as dataFetcher from '../../../../evaluation/domain/services/algorithm-methods/data-fetcher.js';
import { convertLevelStagesIntoThresholds } from '../../../../evaluation/domain/services/stages/convert-level-stages-into-thresholds-service.js';
Expand All @@ -12,9 +15,6 @@ import * as areaRepository from '../../../../shared/infrastructure/repositories/
import * as challengeRepository from '../../../../shared/infrastructure/repositories/challenge-repository.js';
import * as competenceRepository from '../../../../shared/infrastructure/repositories/competence-repository.js';
import * as skillRepository from '../../../../shared/infrastructure/repositories/skill-repository.js';
import * as campaignRepository from '../../../../../lib/infrastructure/repositories/campaign-repository.js';
import * as flashAssessmentResultRepository from '../../../../../lib/infrastructure/repositories/flash-assessment-result-repository.js';
import * as knowledgeElementRepository from '../../../../../lib/infrastructure/repositories/knowledge-element-repository.js';

/**
*
Expand Down
Loading

0 comments on commit c0a8f97

Please sign in to comment.