From 39f46a596c40c1a648a2ac6feb4b5c8978c85801 Mon Sep 17 00:00:00 2001 From: "sebastien.arod@gmail.com" Date: Thu, 6 Jun 2024 21:48:10 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Am=C3=A9liore=20gestion=20des=20Date=20?= =?UTF-8?q?d'=C3=A9venement=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/data/EvenementFamille.ts | 9 ++++++--- src/data/checkDataConsistency.ts | 12 +++++++++++- src/index.ts | 9 +++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/data/EvenementFamille.ts b/src/data/EvenementFamille.ts index 5d38fb0..1b278be 100644 --- a/src/data/EvenementFamille.ts +++ b/src/data/EvenementFamille.ts @@ -81,12 +81,15 @@ export type CategorieEvenement = export function isEvenementInPeriod( evt: EvenementFamille, period: Period -): unknown { - return evt.Date && isPeriodContaining(period, evt.Date); +): boolean { + return evt.Date !== null && isPeriodContaining(period, evt.Date); } export function isEvenementBefore(evt: EvenementFamille, date: Date): boolean { - return evt.Date !== null && evt.Date < date; + if (evt.Date === null) { + return true; + } + return evt.Date < date; } export function isValidEvenementFamille(str: string | null): boolean { diff --git a/src/data/checkDataConsistency.ts b/src/data/checkDataConsistency.ts index dd91e75..2297268 100644 --- a/src/data/checkDataConsistency.ts +++ b/src/data/checkDataConsistency.ts @@ -10,6 +10,7 @@ export function checkDataConsistency(families: Famille[]): ConsistencyIssue[] { export type ConsistencyIssue = { issueType: string; familyId: string; + canIgnore?: boolean; }; function checkFamilyDataConsistency(family: Famille) { const consistencyIssues: ConsistencyIssue[] = []; @@ -51,7 +52,16 @@ function checkFamilyDataConsistency(family: Famille) { ...family.Evenements.filter((e) => !isValidEvenementFamille(e.Type)).map( (e) => ({ familyId: family.Titre, - issueType: "Unknown event Type: " + e.Type, + issueType: `Event ${e.notionId} has unknown event Type "${e.Type}"`, + }) + ) + ); + consistencyIssues.push( + ...family.Evenements.filter((e) => e.Type !== null && e.Date === null).map( + (e) => ({ + familyId: family.Titre, + issueType: `Event ${e.notionId} with non null Type "${e.Type}" but null Date`, + canIgnore: true, }) ) ); diff --git a/src/index.ts b/src/index.ts index 4e69d1b..c904dac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,10 +23,11 @@ import { computeELStats } from "./statistiques/computeELStats"; console.log("Checking Data Consistency issues..."); const consistencyIssues = checkDataConsistency(families); if (consistencyIssues.length > 0) { - console.log("Found consistency issues:"); - console.log(consistencyIssues); - console.log("Exiting."); - process.exit(1); + console.error("Found consistency issues:"); + console.error(consistencyIssues); + if (consistencyIssues.find((issue) => !issue.canIgnore)) { + process.exit(1); + } } const currentDate = new Date(Date.now());