Skip to content

Commit 6779605

Browse files
committed
feat(api+admin): certification structure update page now also update a certification certification authorities
1 parent 3926ea5 commit 6779605

File tree

11 files changed

+115
-34
lines changed

11 files changed

+115
-34
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"data": {
3+
"certification_authority_getCertificationAuthorityStructure": {
4+
"id": "0ec61d50-a202-4222-95ff-d516b9cae503",
5+
"certificationAuthorities": [
6+
{
7+
"id": "47954f7a-1148-4280-842b-01eecf8ac52d",
8+
"label": "Ministère de l'Education Nationale et de la Jeunesse - Auvergne - Rhône-Alpes"
9+
},
10+
{
11+
"id": "39c45c3d-4785-4745-8f24-5cb11c47896e",
12+
"label": "Ministère de l'Education Nationale et de la Jeunesse - Bourgogne - Franche-Comté"
13+
},
14+
{
15+
"id": "dd2aaae3-3d59-45a0-8448-804d3f713bda",
16+
"label": "Ministère de l'Education Nationale et de la Jeunesse - Bretagne"
17+
}
18+
]
19+
}
20+
}
21+
}

packages/reva-admin-react/cypress/e2e/certifications/update-certificaton-structure-page/fixtures/certification-bp-boucher.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"certificationAuthorityStructure": {
77
"id": "0ec61d50-a202-4222-95ff-d516b9cae503",
88
"label": "Ministère de l'Education Nationale et de la Jeunesse"
9-
}
9+
},
10+
"certificationAuthorities": []
1011
},
1112
"certification_authority_getCertificationAuthorityStructures": {
1213
"rows": [

packages/reva-admin-react/cypress/e2e/certifications/update-certificaton-structure-page/update-certification-structure-page.cy.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { stubMutation, stubQuery } from "../../../utils/graphql";
22
import certificationBPBoucher from "./fixtures/certification-bp-boucher.json";
33
import updateCertificationStructureMutationResponse from "./fixtures/update-certification-structure-mutation-response.json";
4+
import certificationAuthoritiesEducNat from "./fixtures/certification-authorities-educ-nat.json";
45

56
function interceptCertification() {
67
cy.intercept("POST", "/api/graphql", (req) => {
@@ -19,6 +20,11 @@ function interceptCertification() {
1920
"getCertificationStructureAndGestionnairesForUpdateCertificationStructurePage",
2021
certificationBPBoucher,
2122
);
23+
stubQuery(
24+
req,
25+
"getCertificationAuthoritiesForUpdateCertificationStructurePage",
26+
certificationAuthoritiesEducNat,
27+
);
2228
});
2329
}
2430

@@ -44,6 +50,7 @@ context("when i access the update certification page ", () => {
4450
cy.wait(
4551
"@getCertificationStructureAndGestionnairesForUpdateCertificationStructurePage",
4652
);
53+
cy.wait("@getCertificationAuthoritiesForUpdateCertificationStructurePage");
4754

4855
cy.get('[data-test="update-certification-structure-page"]')
4956
.children("h1")
@@ -61,9 +68,11 @@ context("when i access the update certification page ", () => {
6168
cy.wait(
6269
"@getCertificationStructureAndGestionnairesForUpdateCertificationStructurePage",
6370
);
71+
cy.wait("@getCertificationAuthoritiesForUpdateCertificationStructurePage");
6472
cy.get(
6573
'[data-test="certification-authority-structure-select"] select',
6674
).select("IPERIA");
75+
cy.wait("@getCertificationAuthoritiesForUpdateCertificationStructurePage");
6776

6877
cy.get("button").contains("Enregistrer").click();
6978

packages/reva-admin-react/src/app/(admin)/certifications-v2/[certificationId]/structure/page.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ export default function UpdateCertificationStructurePage() {
2121

2222
const handleFormSubmit = async (data: CertificationStructureFormData) => {
2323
try {
24-
await updateCertificationStructure.mutateAsync(data);
24+
await updateCertificationStructure.mutateAsync({
25+
...data,
26+
certificationAuthorityIds: data.certificationAuthorities
27+
.filter(({ checked }) => checked)
28+
.map(({ id }) => id),
29+
});
2530
successToast("modifications enregistrées");
2631
} catch (e) {
2732
graphqlErrorToast(e);

packages/reva-admin-react/src/app/(admin)/certifications-v2/[certificationId]/structure/updateCertificationStructure.hook.ts

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ const getCertificationStructureAndGestionnairesQuery = graphql(`
2626
}
2727
`);
2828

29-
const updateCertificationStructureMutation = graphql(`
30-
mutation updateCertificationStructureForUpdateCertificationStructurePage(
31-
$input: UpdateCertificationStructureInput!
32-
) {
33-
referential_updateCertificationStructure(input: $input) {
34-
id
29+
const updateCertificationStructureAndCertificationAuthoritiesMutation = graphql(
30+
`
31+
mutation updateCertificationStructureForUpdateCertificationStructurePage(
32+
$input: UpdateCertificationStructureAndCertificationAuthoritiesInput!
33+
) {
34+
referential_updateCertificationStructureAndCertificationAuthorities(
35+
input: $input
36+
) {
37+
id
38+
}
3539
}
36-
}
37-
`);
40+
`,
41+
);
3842

3943
export const useUpdateCertificationStructurePage = ({
4044
certificationId,
@@ -62,12 +66,21 @@ export const useUpdateCertificationStructurePage = ({
6266
const updateCertificationStructure = useMutation({
6367
mutationFn: ({
6468
certificationAuthorityStructureId,
69+
certificationAuthorityIds,
6570
}: {
6671
certificationAuthorityStructureId: string;
72+
certificationAuthorityIds: string[];
6773
}) =>
68-
graphqlClient.request(updateCertificationStructureMutation, {
69-
input: { certificationId, certificationAuthorityStructureId },
70-
}),
74+
graphqlClient.request(
75+
updateCertificationStructureAndCertificationAuthoritiesMutation,
76+
{
77+
input: {
78+
certificationId,
79+
certificationAuthorityStructureId,
80+
certificationAuthorityIds,
81+
},
82+
},
83+
),
7184
onSuccess: () =>
7285
queryClient.invalidateQueries({
7386
queryKey: [certificationId],

packages/reva-api/modules/referential/features/updateCertificationStructure.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { prismaClient } from "../../../prisma/client";
2+
import { UpdateCertificationStructureAndCertificationAuthoritiesInput } from "../referential.types";
3+
4+
export const updateCertificationStructureAndCertificationAuthorities = async ({
5+
certificationId,
6+
certificationAuthorityStructureId,
7+
certificationAuthorityIds,
8+
}: UpdateCertificationStructureAndCertificationAuthoritiesInput) =>
9+
prismaClient
10+
.$transaction([
11+
prismaClient.certification.update({
12+
where: { id: certificationId },
13+
data: {
14+
certificationAuthorityOnCertification: { deleteMany: {} },
15+
},
16+
}),
17+
prismaClient.certification.update({
18+
where: { id: certificationId },
19+
data: {
20+
certificationAuthorityOnCertification: {
21+
createMany: {
22+
data: certificationAuthorityIds.map((id) => ({
23+
certificationAuthorityId: id,
24+
})),
25+
},
26+
},
27+
},
28+
}),
29+
prismaClient.certification.update({
30+
where: { id: certificationId },
31+
data: {
32+
certificationAuthorityStructureId,
33+
},
34+
}),
35+
])
36+
.then((r) => r[r.length - 1]);

packages/reva-api/modules/referential/referential.graphql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,10 @@ input CreateCompetenceBlocInput {
336336
competences: [CompetenceInput!]!
337337
}
338338

339-
input UpdateCertificationStructureInput {
339+
input UpdateCertificationStructureAndCertificationAuthoritiesInput {
340340
certificationId: ID!
341341
certificationAuthorityStructureId: String!
342+
certificationAuthorityIds: [String!]!
342343
}
343344

344345
input SendCertificationToRegistryManagerInput {
@@ -365,8 +366,8 @@ type Mutation {
365366
certificationCompetenceBlocId: String!
366367
): CertificationCompetenceBloc!
367368
referential_addCertification(input: AddCertificationInput!): Certification!
368-
referential_updateCertificationStructure(
369-
input: UpdateCertificationStructureInput
369+
referential_updateCertificationStructureAndCertificationAuthorities(
370+
input: UpdateCertificationStructureAndCertificationAuthoritiesInput
370371
): Certification!
371372
referential_sendCertificationToRegistryManager(
372373
input: SendCertificationToRegistryManagerInput

packages/reva-api/modules/referential/referential.resolvers.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
UpdateCertificationInput,
2626
UpdateCompetenceBlocInput,
2727
UpdateCompetenceBlocsInput,
28-
UpdateCertificationStructureInput,
28+
UpdateCertificationStructureAndCertificationAuthoritiesInput,
2929
SendCertificationToRegistryManagerInput,
3030
} from "./referential.types";
3131
import { RNCPCertification, RNCPReferential } from "./rncp";
@@ -48,7 +48,7 @@ import { getCompetenceBlocsByCertificationIdV2 } from "./features/getCompetenceB
4848
import { getDomainsByCertificationId } from "./features/getDomainsByCertificationId";
4949
import { getDomainsByFormacodes } from "./features/getDomainsByFormacodes";
5050
import { createCertificationCompetenceBloc } from "./features/createCertificationCompetenceBloc";
51-
import { updateCertificationStructure } from "./features/updateCertificationStructure";
51+
import { updateCertificationStructureAndCertificationAuthorities } from "./features/updateCertificationStructureAndCertificationAuthorities";
5252
import { sendCertificationToRegistryManager } from "./features/sendCertificationToRegistryManager";
5353

5454
const unsafeReferentialResolvers = {
@@ -207,10 +207,14 @@ const unsafeReferentialResolvers = {
207207
_parent: unknown,
208208
{ input }: { input: { codeRncp: string } },
209209
) => addCertification(input),
210-
referential_updateCertificationStructure: (
210+
referential_updateCertificationStructureAndCertificationAuthorities: (
211211
_parent: unknown,
212-
{ input }: { input: UpdateCertificationStructureInput },
213-
) => updateCertificationStructure(input),
212+
{
213+
input,
214+
}: {
215+
input: UpdateCertificationStructureAndCertificationAuthoritiesInput;
216+
},
217+
) => updateCertificationStructureAndCertificationAuthorities(input),
214218
referential_sendCertificationToRegistryManager: (
215219
_parent: unknown,
216220
{ input }: { input: SendCertificationToRegistryManagerInput },

packages/reva-api/modules/referential/referential.security.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const referentialResolversSecurityMap = {
2121
"Mutation.referential_deleteCertificationCompetenceBloc": [
2222
hasRole(["admin"]),
2323
],
24-
"Mutation.referential_updateCertificationStructure": [hasRole(["admin"])],
24+
"Mutation.referential_updateCertificationStructureAndCertificationAuthorities":
25+
[hasRole(["admin"])],
2526
"Mutation.referential_sendCertificationToRegistryManager": [
2627
hasRole(["admin"]),
2728
],

0 commit comments

Comments
 (0)