Skip to content

Commit 616e4de

Browse files
authored
feat(api): add endpoints, tests for backend and front integration of … (#4)
* feat(api): add endpoints, tests for backend and front integration of crud for sections, items, templates, ... * fix(api): fix requested by reviewers
1 parent 78aa729 commit 616e4de

71 files changed

Lines changed: 4911 additions & 567 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

@apps/backend/src/app/app.router.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import {
22
type AuthModule,
33
type UserModule,
44
type CurriculumModule,
5-
ProposedSectionsModule,
5+
type SectionTemplatesModule,
6+
type SectionsModule,
7+
type SectionItemsModule,
68
} from "@libs/users-backend";
79
import type { FastifyInstanceType } from "./app.js";
810
import { statusRoute } from "./status.route.js";
@@ -11,12 +13,21 @@ interface AppRouterOptions {
1113
authModule: AuthModule;
1214
userModule: UserModule;
1315
curriculumModule: CurriculumModule;
14-
proposedSectionsModule: ProposedSectionsModule;
16+
sectionTemplatesModule: SectionTemplatesModule;
17+
sectionsModule: SectionsModule;
18+
sectionItemsModule: SectionItemsModule;
1519
}
1620

1721
export async function appRouter(
1822
fastify: FastifyInstanceType,
19-
{ authModule, userModule, curriculumModule, proposedSectionsModule }: AppRouterOptions,
23+
{
24+
authModule,
25+
userModule,
26+
curriculumModule,
27+
sectionTemplatesModule,
28+
sectionsModule,
29+
sectionItemsModule,
30+
}: AppRouterOptions,
2031
) {
2132
await fastify.register(
2233
async function (fastify) {
@@ -33,7 +44,9 @@ export async function appRouter(
3344

3445
await userModule.setupRoutes(fastify);
3546
await curriculumModule.setupRoutes(fastify);
36-
await proposedSectionsModule.setupRoutes(fastify);
47+
await sectionTemplatesModule.setupRoutes(fastify);
48+
await sectionsModule.setupRoutes(fastify);
49+
await sectionItemsModule.setupRoutes(fastify);
3750
},
3851
{
3952
prefix: "api/v1",

@apps/backend/src/app/app.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import {
2323
UserModule,
2424
AuthModule,
2525
CurriculumModule,
26-
ProposedSectionsModule,
26+
SectionTemplatesModule,
27+
SectionsModule,
28+
SectionItemsModule,
2729
} from "@libs/users-backend";
2830

2931
export type FastifyInstanceType = FastifyInstance<
@@ -173,7 +175,19 @@ export class App {
173175
jwtSecret: this.context.configuration.JWT_SECRET,
174176
},
175177
}),
176-
proposedSectionsModule: ProposedSectionsModule.init({
178+
sectionTemplatesModule: SectionTemplatesModule.init({
179+
em: this.context.orm.em.fork(),
180+
configuration: {
181+
jwtSecret: this.context.configuration.JWT_SECRET,
182+
},
183+
}),
184+
sectionsModule: SectionsModule.init({
185+
em: this.context.orm.em.fork(),
186+
configuration: {
187+
jwtSecret: this.context.configuration.JWT_SECRET,
188+
},
189+
}),
190+
sectionItemsModule: SectionItemsModule.init({
177191
em: this.context.orm.em.fork(),
178192
configuration: {
179193
jwtSecret: this.context.configuration.JWT_SECRET,

@apps/backend/src/app/database.connection.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
RefreshTokenEntity,
55
UserEntity,
66
CurriculumEntity,
7-
ProposedSectionEntity,
7+
SectionTemplatesEntity,
8+
SectionsEntity,
9+
SectionItemsEntity,
810
} from "@libs/users-backend";
911

1012
export function databaseConfig(config: Pick<AppConfiguration, "DATABASE_URI">) {
@@ -13,7 +15,14 @@ export function databaseConfig(config: Pick<AppConfiguration, "DATABASE_URI">) {
1315
pathTs: "./src/seeders",
1416
},
1517
clientUrl: config.DATABASE_URI,
16-
entities: [UserEntity, RefreshTokenEntity, CurriculumEntity, ProposedSectionEntity],
18+
entities: [
19+
UserEntity,
20+
RefreshTokenEntity,
21+
CurriculumEntity,
22+
SectionTemplatesEntity,
23+
SectionsEntity,
24+
SectionItemsEntity,
25+
],
1726
});
1827
}
1928

@apps/backend/src/mikro-orm.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ const config = loadConfiguration();
99
* Important for test reproduction
1010
*/
1111
seed(config.SEED);
12-
1312
export default defineConfig(databaseConfig(config));
Lines changed: 128 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
import { hashPassword, ProposedSectionEntity, UserEntity } from "@libs/users-backend";
1+
import {
2+
hashPassword,
3+
SectionTemplatesEntity,
4+
UserEntity,
5+
CurriculumEntity,
6+
SectionsEntity,
7+
SectionItemsEntity,
8+
} from "@libs/users-backend";
29
import type { EntityManager } from "@mikro-orm/core";
310
import { Seeder } from "@mikro-orm/seeder";
11+
import personnalInformationsJsonSchema from "./models/personal-informations.schema.json" with { type: "json" };
12+
import formationsJsonSchema from "./models/formations.schema.json" with { type: "json" };
13+
import langueJsonSchema from "./models/langues.schema.json" with { type: "json" };
14+
import centresInteretsJsonSchema from "./models/centres-interets.schema.json" with { type: "json" };
15+
import competencesJsonSchema from "./models/competences.schema.json" with { type: "json" };
16+
import experiencesJsonSchema from "./models/experiences.schema.json" with { type: "json" };
17+
import profilJsonSchema from "./models/profil.schema.json" with { type: "json" };
18+
import referencesJsonSchema from "./models/references.schema.json" with { type: "json" };
419

520
export class DatabaseSeeder extends Seeder {
621
async run(em: EntityManager) {
@@ -15,22 +30,125 @@ export class DatabaseSeeder extends Seeder {
1530
password: hashedPassword,
1631
});
1732

18-
em.create(ProposedSectionEntity, {
19-
id: "e2e-proposed-section-1",
20-
title: "Informations personnelles",
33+
const template1 = em.create(SectionTemplatesEntity, {
34+
id: "e2e-section-template-1",
35+
label: "Informations personnelles",
36+
jsonSchema: personnalInformationsJsonSchema,
2137
position: 1,
2238
});
2339

24-
em.create(ProposedSectionEntity, {
25-
id: "e2e-proposed-section-2",
26-
title: "Expérience professionnelle",
40+
const template2 = em.create(SectionTemplatesEntity, {
41+
id: "e2e-section-template-2",
42+
label: "Formations",
43+
jsonSchema: formationsJsonSchema,
2744
position: 2,
2845
});
2946

30-
em.create(ProposedSectionEntity, {
31-
id: "e2e-proposed-section-3",
32-
title: "Formation et diplômes",
47+
em.create(SectionTemplatesEntity, {
48+
id: "e2e-section-template-3",
49+
label: "Expériences professionnelles",
50+
jsonSchema: experiencesJsonSchema,
3351
position: 3,
3452
});
53+
54+
em.create(SectionTemplatesEntity, {
55+
id: "e2e-section-template-4",
56+
label: "Compétences",
57+
jsonSchema: competencesJsonSchema,
58+
position: 4,
59+
});
60+
61+
em.create(SectionTemplatesEntity, {
62+
id: "e2e-section-template-5",
63+
label: "Centres d'intérêts",
64+
jsonSchema: centresInteretsJsonSchema,
65+
position: 5,
66+
});
67+
68+
em.create(SectionTemplatesEntity, {
69+
id: "e2e-section-template-6",
70+
label: "Profil",
71+
jsonSchema: profilJsonSchema,
72+
position: 6,
73+
});
74+
75+
em.create(SectionTemplatesEntity, {
76+
id: "e2e-section-template-7",
77+
label: "Références",
78+
jsonSchema: referencesJsonSchema,
79+
position: 7,
80+
});
81+
82+
em.create(SectionTemplatesEntity, {
83+
id: "e2e-section-template-8",
84+
label: "Langues",
85+
jsonSchema: langueJsonSchema,
86+
position: 8,
87+
});
88+
89+
const curriculum = em.create(CurriculumEntity, {
90+
id: "e2e-curriculum",
91+
userId: "e2e-login-user",
92+
title: "Mon CV",
93+
createdAt: new Date(),
94+
updatedAt: new Date(),
95+
});
96+
97+
const section1 = em.create(SectionsEntity, {
98+
id: "e2e-section-1",
99+
curriculum,
100+
template: template1,
101+
title: "Informations personnelles",
102+
position: 1,
103+
});
104+
105+
const section2 = em.create(SectionsEntity, {
106+
id: "e2e-section-2",
107+
curriculum,
108+
template: template2,
109+
title: "Formations",
110+
position: 2,
111+
});
112+
113+
em.create(SectionItemsEntity, {
114+
id: "e2e-section-item-1",
115+
section: section1,
116+
position: 1,
117+
jsonData: {
118+
firstName: "Amaury",
119+
lastName: "Deflorenne",
120+
email: "test@gmail.com",
121+
phone: "0601020304",
122+
address: "123 rue de la paix, 75000 Paris",
123+
},
124+
});
125+
126+
em.create(SectionItemsEntity, {
127+
id: "e2e-section-item-2",
128+
section: section2,
129+
position: 1,
130+
jsonData: {
131+
school: "Université de Lyon",
132+
degree: "Master Informatique",
133+
field: "Informatique",
134+
startDate: "2021-09-01",
135+
endDate: "2023-06-30",
136+
description: "Description de ma formation en informatique à l'Université de Lyon.",
137+
},
138+
});
139+
140+
em.create(SectionItemsEntity, {
141+
id: "e2e-section-item-3",
142+
section: section2,
143+
position: 2,
144+
jsonData: {
145+
school: "Université de Paris",
146+
degree: "Licence Informatique",
147+
field: "Informatique",
148+
startDate: "2018-09-01",
149+
endDate: "2021-06-30",
150+
description: "Description de ma formation en informatique à l'Université de Paris.",
151+
},
152+
});
35153
}
36154
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{ "key": "interest", "label": "Centre d'intérêt", "type": "text" }]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
{ "key": "competence", "label": "Compétence", "type": "text" },
3+
{ "key": "level", "label": "Niveau", "type": "text" }
4+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{ "key": "position", "label": "Poste", "type": "text" },
3+
{ "key": "employer", "label": "Employeur", "type": "text" },
4+
{ "key": "city", "label": "Ville", "type": "text" },
5+
{ "key": "startDate", "label": "Date de début", "type": "date" },
6+
{ "key": "endDate", "label": "Date de fin", "type": "date" },
7+
{ "key": "description", "label": "Description", "type": "textarea" }
8+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{ "key": "school", "label": "École / Université", "type": "text" },
3+
{ "key": "degree", "label": "Diplôme", "type": "text" },
4+
{ "key": "field", "label": "Domaine", "type": "text" },
5+
{ "key": "startDate", "label": "Début", "type": "date" },
6+
{ "key": "endDate", "label": "Fin", "type": "date" },
7+
{ "key": "description", "label": "Description", "type": "textarea" }
8+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[
2+
{ "key": "langue", "label": "Langue", "type": "text" },
3+
{ "key": "niveau", "label": "Niveau", "type": "text" }
4+
]

0 commit comments

Comments
 (0)