Skip to content

Commit 1dc6ff7

Browse files
committed
feat(api): updated api to start using the new certification authority <-> certificationAuthorityStructure relationship
1 parent 3437ef4 commit 1dc6ff7

File tree

9 files changed

+207
-171
lines changed

9 files changed

+207
-171
lines changed

packages/reva-api/modules/candidacy/security/candidacy.security.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ test("Certification local account of the feasibility file of the candidacy shoul
195195
const certification = await createCertificationHelper({
196196
certificationAuthorityStructureId:
197197
certificationAuthorityLocalAccount.certificationAuthority
198-
.oldCertificationAuthorityStructureId,
198+
.certificationAuthorityOnCertificationAuthorityStructure[0]
199+
?.certificationAuthorityStructureId,
199200
});
200201
const candidacyInput = await createCandidacyHelper({
201202
candidacyArgs: {

packages/reva-api/modules/certification-authority/features/createCertificationAuthority.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ export const createCertificationAuthority = async ({
4242
},
4343
},
4444
oldCertificationAuthorityStructureId: certificationAuthorityStructureId,
45+
certificationAuthorityOnCertificationAuthorityStructure: {
46+
create: {
47+
certificationAuthorityStructureId:
48+
certificationAuthorityStructureId,
49+
},
50+
},
4551
label,
4652
contactEmail,
4753
contactFullName,

packages/reva-api/modules/certification-authority/features/getCertificationAuthoritiesByStructureId.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,12 @@ export async function getCertificationAuthoritiesByStructureId(
1010
id: structureId,
1111
},
1212
})
13-
.oldCertificationAuthorities();
13+
.certificationAuthorityOnCertificationAuthorityStructure({
14+
include: { certificationAuthority: true },
15+
orderBy: { certificationAuthority: { label: "asc" } },
16+
})
17+
.then(
18+
(caocass) =>
19+
caocass?.map((caocas) => caocas.certificationAuthority) || [],
20+
);
1421
}

packages/reva-api/modules/feasibility/feasibility.test.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ test("should count all (1) available feasibility for certificator user even if o
4747
const certification = await createCertificationHelper({});
4848
const certificationAuthority =
4949
certification.certificationAuthorityStructure
50-
?.oldCertificationAuthorities[0];
50+
?.certificationAuthorityOnCertificationAuthorityStructure[0]
51+
?.certificationAuthority;
5152
const candidacy = await createCandidacyHelper({
5253
candidacyArgs: {
5354
certificationId: certification.id,
@@ -109,7 +110,8 @@ test("should return a feasibilty for certificator since he is allowed to handle
109110
const certification = await createCertificationHelper({});
110111
const certificationAuthority =
111112
certification.certificationAuthorityStructure
112-
?.oldCertificationAuthorities[0];
113+
?.certificationAuthorityOnCertificationAuthorityStructure[0]
114+
?.certificationAuthority;
113115
const candidacy = await createCandidacyHelper({
114116
candidacyArgs: {
115117
certificationId: certification.id,
@@ -170,7 +172,8 @@ test("should return all (1) available feasibility for certificateur user", async
170172
const certification = await createCertificationHelper({});
171173
const certificationAuthority =
172174
certification.certificationAuthorityStructure
173-
?.oldCertificationAuthorities[0];
175+
?.certificationAuthorityOnCertificationAuthorityStructure[0]
176+
?.certificationAuthority;
174177
const candidacy = await createCandidacyHelper({
175178
candidacyArgs: {
176179
certificationId: certification.id,
@@ -257,7 +260,8 @@ test("should validate a feasibility since certificator is allowed to do so", asy
257260
const certification = await createCertificationHelper({});
258261
const certificationAuthority =
259262
certification.certificationAuthorityStructure
260-
?.oldCertificationAuthorities[0];
263+
?.certificationAuthorityOnCertificationAuthorityStructure[0]
264+
?.certificationAuthority;
261265
const candidacy = await createCandidacyHelper({
262266
candidacyArgs: {
263267
certificationId: certification.id,
@@ -323,7 +327,8 @@ test("should reject a feasibility since certificator is allowed to do so", async
323327
const certification = await createCertificationHelper({});
324328
const certificationAuthority =
325329
certification.certificationAuthorityStructure
326-
?.oldCertificationAuthorities[0];
330+
?.certificationAuthorityOnCertificationAuthorityStructure[0]
331+
?.certificationAuthority;
327332
const candidacy = await createCandidacyHelper({
328333
candidacyArgs: {
329334
certificationId: certification.id,

packages/reva-api/prisma/schema.prisma

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,8 @@ model CertificationAuthorityStructure {
916916
certifications Certification[]
917917
oldCertificationAuthorities CertificationAuthority[] @relation("old_certification_authority_on_certification_authority_structure")
918918
919-
certificationRegistryManager CertificationRegistryManager?
920-
certificationAuthorityStructureOnCertificationAuthorityStructure CertificationAuthorityOnCertificationAuthorityStructure[]
919+
certificationRegistryManager CertificationRegistryManager?
920+
certificationAuthorityOnCertificationAuthorityStructure CertificationAuthorityOnCertificationAuthorityStructure[]
921921
922922
@@map("certification_authority_structure")
923923
}
Lines changed: 100 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,100 @@
1-
import {
2-
Candidacy,
3-
CandidacyStatusStep,
4-
CandidateTypology,
5-
FinanceModule,
6-
} from "@prisma/client";
7-
import { prismaClient } from "../../../prisma/client";
8-
import { BASIC_SKILL_1, BASIC_SKILL_2 } from "../../../test/fixtures";
9-
import { createCandidateHelper } from "./create-candidate-helper";
10-
import { createCertificationHelper } from "./create-certification-helper";
11-
import { createOrganismHelper } from "./create-organism-helper";
12-
13-
export const createCandidacyHelper = async (args?: {
14-
candidacyArgs?: Partial<Candidacy>;
15-
candidacyActiveStatus?: CandidacyStatusStep;
16-
}) => {
17-
const { candidacyArgs, candidacyActiveStatus } = args ?? {};
18-
19-
const certification = await createCertificationHelper();
20-
const department = await prismaClient.department.findFirst({
21-
where: { code: "75" },
22-
});
23-
const candidate = await createCandidateHelper();
24-
25-
const organism = candidacyArgs?.organismId
26-
? await prismaClient.organism.findUnique({
27-
where: { id: candidacyArgs?.organismId },
28-
})
29-
: await createOrganismHelper();
30-
31-
if (!organism) {
32-
throw Error("Organism not found");
33-
}
34-
35-
const basicSkillId1 = (
36-
await prismaClient.basicSkill.findFirstOrThrow({
37-
where: {
38-
label: BASIC_SKILL_1,
39-
},
40-
})
41-
).id;
42-
43-
const basicSkillId2 = (
44-
await prismaClient.basicSkill.findFirstOrThrow({
45-
where: {
46-
label: BASIC_SKILL_2,
47-
},
48-
})
49-
).id;
50-
51-
return prismaClient.candidacy.create({
52-
data: {
53-
typology: CandidateTypology.BENEVOLE,
54-
financeModule: FinanceModule.unifvae,
55-
isCertificationPartial: false,
56-
status: candidacyActiveStatus ?? CandidacyStatusStep.PARCOURS_CONFIRME,
57-
departmentId: department?.id ?? "",
58-
basicSkills: {
59-
createMany: {
60-
data: [
61-
{ basicSkillId: basicSkillId1 },
62-
{ basicSkillId: basicSkillId2 },
63-
],
64-
},
65-
},
66-
certificationId: certification.id,
67-
candidateId: candidate.id,
68-
organismId: organism.id,
69-
candidacyStatuses: {
70-
create: {
71-
status:
72-
candidacyActiveStatus ?? CandidacyStatusStep.PARCOURS_CONFIRME,
73-
isActive: true,
74-
},
75-
},
76-
...candidacyArgs,
77-
},
78-
include: {
79-
certification: {
80-
include: {
81-
certificationAuthorityStructure: {
82-
include: {
83-
oldCertificationAuthorities: { include: { Account: true } },
84-
certificationRegistryManager: { include: { account: true } },
85-
},
86-
},
87-
},
88-
},
89-
organism: { include: { accounts: true } },
90-
candidate: true,
91-
candidacyDropOut: true,
92-
candidacyStatuses: true,
93-
department: true,
94-
},
95-
});
96-
};
1+
import {
2+
Candidacy,
3+
CandidacyStatusStep,
4+
CandidateTypology,
5+
FinanceModule,
6+
} from "@prisma/client";
7+
import { prismaClient } from "../../../prisma/client";
8+
import { BASIC_SKILL_1, BASIC_SKILL_2 } from "../../../test/fixtures";
9+
import { createCandidateHelper } from "./create-candidate-helper";
10+
import { createCertificationHelper } from "./create-certification-helper";
11+
import { createOrganismHelper } from "./create-organism-helper";
12+
13+
export const createCandidacyHelper = async (args?: {
14+
candidacyArgs?: Partial<Candidacy>;
15+
candidacyActiveStatus?: CandidacyStatusStep;
16+
}) => {
17+
const { candidacyArgs, candidacyActiveStatus } = args ?? {};
18+
19+
const certification = await createCertificationHelper();
20+
const department = await prismaClient.department.findFirst({
21+
where: { code: "75" },
22+
});
23+
const candidate = await createCandidateHelper();
24+
25+
const organism = candidacyArgs?.organismId
26+
? await prismaClient.organism.findUnique({
27+
where: { id: candidacyArgs?.organismId },
28+
})
29+
: await createOrganismHelper();
30+
31+
if (!organism) {
32+
throw Error("Organism not found");
33+
}
34+
35+
const basicSkillId1 = (
36+
await prismaClient.basicSkill.findFirstOrThrow({
37+
where: {
38+
label: BASIC_SKILL_1,
39+
},
40+
})
41+
).id;
42+
43+
const basicSkillId2 = (
44+
await prismaClient.basicSkill.findFirstOrThrow({
45+
where: {
46+
label: BASIC_SKILL_2,
47+
},
48+
})
49+
).id;
50+
51+
return prismaClient.candidacy.create({
52+
data: {
53+
typology: CandidateTypology.BENEVOLE,
54+
financeModule: FinanceModule.unifvae,
55+
isCertificationPartial: false,
56+
status: candidacyActiveStatus ?? CandidacyStatusStep.PARCOURS_CONFIRME,
57+
departmentId: department?.id ?? "",
58+
basicSkills: {
59+
createMany: {
60+
data: [
61+
{ basicSkillId: basicSkillId1 },
62+
{ basicSkillId: basicSkillId2 },
63+
],
64+
},
65+
},
66+
certificationId: certification.id,
67+
candidateId: candidate.id,
68+
organismId: organism.id,
69+
candidacyStatuses: {
70+
create: {
71+
status:
72+
candidacyActiveStatus ?? CandidacyStatusStep.PARCOURS_CONFIRME,
73+
isActive: true,
74+
},
75+
},
76+
...candidacyArgs,
77+
},
78+
include: {
79+
certification: {
80+
include: {
81+
certificationAuthorityStructure: {
82+
include: {
83+
certificationAuthorityOnCertificationAuthorityStructure: {
84+
include: {
85+
certificationAuthority: { include: { Account: true } },
86+
},
87+
},
88+
certificationRegistryManager: { include: { account: true } },
89+
},
90+
},
91+
},
92+
},
93+
organism: { include: { accounts: true } },
94+
candidate: true,
95+
candidacyDropOut: true,
96+
candidacyStatuses: true,
97+
department: true,
98+
},
99+
});
100+
};
Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
1-
import { faker } from "@faker-js/faker";
2-
import { prismaClient } from "../../../prisma/client";
3-
import { CertificationAuthority } from "@prisma/client";
4-
import { createCertificationAuthorityStructureHelper } from "./create-certification-authority-structure-helper";
5-
6-
export const createCertificationAuthorityHelper = async (
7-
certificationAuthorityArgs?: Partial<CertificationAuthority>,
8-
) => {
9-
const certificationAuthorityStructure =
10-
await createCertificationAuthorityStructureHelper();
11-
12-
return prismaClient.certificationAuthority.create({
13-
data: {
14-
contactEmail: faker.internet.email(),
15-
contactFullName: faker.person.fullName(),
16-
label: faker.company.name(),
17-
oldCertificationAuthorityStructureId: certificationAuthorityStructure.id,
18-
...certificationAuthorityArgs,
19-
Account: {
20-
create: {
21-
email: faker.internet.email(),
22-
firstname: faker.person.firstName(),
23-
lastname: faker.person.lastName(),
24-
keycloakId: faker.string.uuid(),
25-
},
26-
},
27-
},
28-
include: {
29-
oldCertificationAuthorityStructure: true,
30-
Account: true,
31-
},
32-
});
33-
};
1+
import { faker } from "@faker-js/faker";
2+
import { prismaClient } from "../../../prisma/client";
3+
import { CertificationAuthority } from "@prisma/client";
4+
import { createCertificationAuthorityStructureHelper } from "./create-certification-authority-structure-helper";
5+
6+
export const createCertificationAuthorityHelper = async (
7+
certificationAuthorityArgs?: Partial<CertificationAuthority>,
8+
) => {
9+
const certificationAuthorityStructure =
10+
await createCertificationAuthorityStructureHelper();
11+
12+
return prismaClient.certificationAuthority.create({
13+
data: {
14+
contactEmail: faker.internet.email(),
15+
contactFullName: faker.person.fullName(),
16+
label: faker.company.name(),
17+
oldCertificationAuthorityStructureId: certificationAuthorityStructure.id,
18+
certificationAuthorityOnCertificationAuthorityStructure: {
19+
create: {
20+
certificationAuthorityStructureId: certificationAuthorityStructure.id,
21+
},
22+
},
23+
...certificationAuthorityArgs,
24+
Account: {
25+
create: {
26+
email: faker.internet.email(),
27+
firstname: faker.person.firstName(),
28+
lastname: faker.person.lastName(),
29+
keycloakId: faker.string.uuid(),
30+
},
31+
},
32+
},
33+
include: {
34+
certificationAuthorityOnCertificationAuthorityStructure: {
35+
include: { certificationAuthorityStructure: true },
36+
},
37+
Account: true,
38+
},
39+
});
40+
};

0 commit comments

Comments
 (0)