-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TECH] Migrer la route PATCH /api/admin/certification-center-membersh…
- Loading branch information
Showing
10 changed files
with
267 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ation/certification-center-membership/certification-center-membership.admin.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { BadRequestError } from '../../../shared/application/http-errors.js'; | ||
import * as certificationCenterMembershipSerializer from '../../../shared/infrastructure/serializers/jsonapi/certification-center-membership.serializer.js'; | ||
import { requestResponseUtils } from '../../../shared/infrastructure/utils/request-response-utils.js'; | ||
import { usecases } from '../../domain/usecases/index.js'; | ||
|
||
const updateRole = async function ( | ||
request, | ||
h, | ||
dependencies = { requestResponseUtils, certificationCenterMembershipSerializer }, | ||
) { | ||
const certificationCenterMembershipId = request.params.id; | ||
const certificationCenterMembership = dependencies.certificationCenterMembershipSerializer.deserialize( | ||
request.payload, | ||
); | ||
const pixAgentUserId = dependencies.requestResponseUtils.extractUserIdFromRequest(request); | ||
|
||
if (certificationCenterMembershipId !== certificationCenterMembership.id) { | ||
throw new BadRequestError(); | ||
} | ||
|
||
const updatedCertificationCenterMembership = await usecases.updateCertificationCenterMembership({ | ||
certificationCenterMembershipId, | ||
role: certificationCenterMembership.role, | ||
updatedByUserId: pixAgentUserId, | ||
}); | ||
|
||
return h.response( | ||
dependencies.certificationCenterMembershipSerializer.serializeForAdmin(updatedCertificationCenterMembership), | ||
); | ||
}; | ||
|
||
const certificationCenterMembershipAdminController = { | ||
updateRole, | ||
}; | ||
|
||
export { certificationCenterMembershipAdminController }; |
29 changes: 29 additions & 0 deletions
29
...pplication/certification-center-membership/certification-center-membership.admin.route.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { securityPreHandlers } from '../../../shared/application/security-pre-handlers.js'; | ||
import { certificationCenterMembershipAdminController } from './certification-center-membership.admin.controller.js'; | ||
|
||
export const certificationCenterMembershipAdminRoutes = [ | ||
{ | ||
method: 'PATCH', | ||
path: '/api/admin/certification-center-memberships/{id}', | ||
config: { | ||
handler: (request, h) => certificationCenterMembershipAdminController.updateRole(request, h), | ||
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" + | ||
"- Modification du rôle d'un membre d'un centre de certification\n", | ||
], | ||
tags: ['api', 'team', 'admin', 'certification-center-membership'], | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...update-certification-center-membership.js → ...ertification-center-membership.usecase.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.