Skip to content

Commit

Permalink
feat(api): updated addCertification method to auto fill prerequisites…
Browse files Browse the repository at this point in the history
… using the france competences api
  • Loading branch information
agarbe committed Dec 12, 2024
1 parent b2b727e commit 5ff7797
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions packages/reva-api/modules/referential/features/addCertification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ export const addCertification = async (params: { codeRncp: string }) => {
rncpDeliveryDeadline: rncpCertification.DATE_LIMITE_DELIVRANCE
? new Date(rncpCertification.DATE_LIMITE_DELIVRANCE)
: null,
fcPrerequisites: rncpCertification.PREREQUIS.LISTE_PREREQUIS,
prerequisites: {
createMany: {
data: rncpCertification.PREREQUIS.PARSED_PREREQUIS.map((p, i) => ({
label: p,
index: i,
})),
},
},
},
});

Expand All @@ -84,7 +93,10 @@ export const addCertification = async (params: { codeRncp: string }) => {
});

// Create default competence blocs
await createDefaultBlocs({ certificationId: certification.id, codeRncp });
await createDefaultBlocs({
certificationId: certification.id,
rncpCertification,
});

return certification;
};
Expand All @@ -104,15 +116,13 @@ const getLevelFromRNCPCertification = (
}
};

const createDefaultBlocs = async (params: {
const createDefaultBlocs = async ({
certificationId,
rncpCertification,
}: {
certificationId: string;
codeRncp: string;
rncpCertification: RNCPCertification;
}): Promise<CertificationCompetenceBloc[]> => {
const { certificationId, codeRncp } = params;

const rncpCertification =
await RNCPReferential.getInstance().findOneByRncp(codeRncp);

if (rncpCertification) {
for (const bloc of rncpCertification.BLOCS_COMPETENCES) {
const createdBloc = await prismaClient.certificationCompetenceBloc.create(
Expand Down

0 comments on commit 5ff7797

Please sign in to comment.