Skip to content

Commit

Permalink
feat(api): added errors to improve ux for rncp referential
Browse files Browse the repository at this point in the history
  • Loading branch information
fbonniec committed Nov 21, 2024
1 parent 59054b0 commit 79f7184
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ const PageContent = ({
<Info title="Intitulé">{certification.label}</Info>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<Info title="Niveau">{certification.degree.label}</Info>
<Info title="Type">{certification.typeDiplome || ""}</Info>
<Info title="Type">{certification.typeDiplome || "Inconnu"}</Info>
<Info title="Date d’échéance">
{certification.rncpExpiresAt
? format(certification.rncpExpiresAt, "dd/MM/yyyy")
: ""}
: "Inconnue"}
</Info>
<Info title="Date de dernière delivrance">
{certification.rncpDeliveryDeadline
? format(certification.rncpDeliveryDeadline, "dd/MM/yyyy")
: ""}
: "Inconnue"}
</Info>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,25 @@ export default function CertificationDescriptionPage() {
</Info>

<Info title="Niveau">
{certification?.NOMENCLATURE_EUROPE.INTITULE}
{certification?.NOMENCLATURE_EUROPE?.INTITULE || "Inconnu"}
</Info>
<Info title="Type">
{certification.ABREGE
? `${certification.ABREGE.LIBELLE} (${certification.ABREGE.CODE})`
: "Inconnue"}
: "Inconnu"}
</Info>
<Info title="Date d’échéance">
{certification.DATE_FIN_ENREGISTREMENT
? format(
certification.DATE_FIN_ENREGISTREMENT,
"dd/MM/yyyy",
)
: ""}
: "Inconnue"}
</Info>
<Info title="Date de dernière delivrance">
{certification.DATE_LIMITE_DELIVRANCE
? format(certification.DATE_LIMITE_DELIVRANCE, "dd/MM/yyyy")
: ""}
: "Inconnue"}
</Info>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ export const CertificationGeneralInformation = ({
</Info>
<div className="grid grid-cols-2">
<Info title="Niveau de la certification">
{fcCertification.NOMENCLATURE_EUROPE.INTITULE}
{fcCertification.NOMENCLATURE_EUROPE?.INTITULE || "Inconnu"}
</Info>
<Info title="Type de la certification">
{fcCertification.ABREGE
? `${fcCertification.ABREGE.LIBELLE} (${fcCertification.ABREGE.CODE})`
: "Inconnue"}
</Info>
<Info title="Date fin enregistrement">
{format(fcCertification.DATE_FIN_ENREGISTREMENT, "dd/MM/yyyy")}
{fcCertification.DATE_FIN_ENREGISTREMENT
? format(fcCertification.DATE_FIN_ENREGISTREMENT, "dd/MM/yyyy")
: "Inconnue"}
</Info>
<Info title="Date limite délivrance">
{fcCertification.DATE_LIMITE_DELIVRANCE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export const addCertification = async (params: { codeRncp: string }) => {
: rncpCertification.INTITULE;

const availableAt = new Date();

if (!rncpCertification.DATE_FIN_ENREGISTREMENT) {
throw new Error(
`La certification avec le code rncp ${codeRncp} n'a pas de date de fin d'enregistrement`,
);
}
const expiresAt = new Date(rncpCertification.DATE_FIN_ENREGISTREMENT);

const certification = await prismaClient.certification.create({
Expand Down Expand Up @@ -88,7 +94,7 @@ const getLevelFromRNCPCertification = (
): number => {
try {
const strLevel =
certification.NOMENCLATURE_EUROPE.INTITULE.split(" ").reverse()[0];
certification.NOMENCLATURE_EUROPE?.INTITULE.split(" ").reverse()[0] || "";
const level = parseInt(strLevel, 10);
return level;
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export const updateCertificationWithRncpFields = async (params: {
: rncpCertification.INTITULE;

const availableAt = new Date();

if (!rncpCertification.DATE_FIN_ENREGISTREMENT) {
throw new Error(
`La certification avec le code rncp ${codeRncp} n'a pas de date de fin d'enregistrement`,
);
}
const expiresAt = new Date(rncpCertification.DATE_FIN_ENREGISTREMENT);

// Update certification from based on RNCP
Expand Down Expand Up @@ -58,7 +64,7 @@ const getLevelFromRNCPCertification = (
): number => {
try {
const strLevel =
certification.NOMENCLATURE_EUROPE.INTITULE.split(" ").reverse()[0];
certification.NOMENCLATURE_EUROPE?.INTITULE.split(" ").reverse()[0] || "";
const level = parseInt(strLevel, 10);
return level;
} catch {
Expand Down
4 changes: 2 additions & 2 deletions packages/reva-api/modules/referential/referential.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ type FCCertification {
NUMERO_FICHE: String!
INTITULE: String!
ABREGE: FCAbrege
NOMENCLATURE_EUROPE: FCNomenclatureEurope!
DATE_FIN_ENREGISTREMENT: Timestamp!
NOMENCLATURE_EUROPE: FCNomenclatureEurope
DATE_FIN_ENREGISTREMENT: Timestamp
DATE_LIMITE_DELIVRANCE: Timestamp
BLOCS_COMPETENCES: [BlocCompetence!]!
FORMACODES: [FCFormacode!]!
Expand Down
24 changes: 15 additions & 9 deletions packages/reva-api/modules/referential/rncp/referential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ export type RNCPCertification = {
CODE: string;
LIBELLE: string;
};
NOMENCLATURE_EUROPE: {
NOMENCLATURE_EUROPE?: {
NIVEAU: string;
INTITULE: string;
};
DATE_FIN_ENREGISTREMENT: number;
DATE_FIN_ENREGISTREMENT?: number;
DATE_LIMITE_DELIVRANCE?: number;
BLOCS_COMPETENCES: {
CODE: string;
Expand Down Expand Up @@ -113,9 +113,11 @@ export class RNCPReferential {
(acc, value) => {
const certification = mapToRNCPCertification(value);
if (certification) {
return [...acc, certification];
throw new Error(
`La certification avec le code rncp ${value?.NUMERO_FICHE} n'a pas pu être parsée. Veuillez contacter le support technique.`,
);
}
return acc;
return [...acc, certification];
},
[] as RNCPCertification[],
);
Expand Down Expand Up @@ -256,11 +258,15 @@ function mapToRNCPCertification(data: any): RNCPCertification | undefined {
LIBELLE: data.ABREGE.LIBELLE,
}
: undefined,
NOMENCLATURE_EUROPE: {
NIVEAU: data.NOMENCLATURE_EUROPE.NIVEAU,
INTITULE: data.NOMENCLATURE_EUROPE.INTITULE,
},
DATE_FIN_ENREGISTREMENT: getDateFromString(data.DATE_FIN_ENREGISTREMENT),
NOMENCLATURE_EUROPE: data.NOMENCLATURE_EUROPE
? {
NIVEAU: data.NOMENCLATURE_EUROPE.NIVEAU,
INTITULE: data.NOMENCLATURE_EUROPE.INTITULE,
}
: undefined,
DATE_FIN_ENREGISTREMENT: data.DATE_FIN_ENREGISTREMENT
? getDateFromString(data.DATE_FIN_ENREGISTREMENT)
: undefined,
DATE_LIMITE_DELIVRANCE: data.DATE_LIMITE_DELIVRANCE
? getDateFromString(data.DATE_LIMITE_DELIVRANCE)
: undefined,
Expand Down

0 comments on commit 79f7184

Please sign in to comment.