import { isValidEvenementFamille } from "./EvenementFamille"; import { Famille } from "./Famille"; export function checkDataConsistency(families: Famille[]): ConsistencyIssue[] { return families.flatMap((family) => { return checkFamilyDataConsistency(family); }); } export type ConsistencyIssue = { issueType: string; familyId: string; canIgnore?: boolean; }; function checkFamilyDataConsistency(family: Famille) { const consistencyIssues: ConsistencyIssue[] = []; if (family.Statut === "Résistant.e") { if (family.Integration === null) { consistencyIssues.push({ familyId: family.Titre, issueType: "Résistant.e without startResistant", }); } if (family.Sortie !== null) { consistencyIssues.push({ familyId: family.Titre, issueType: "Résistant.e with endResistant!!", }); } } else if (family.Statut === "Ex résistant·e·s") { if (family.Integration === null) { consistencyIssues.push({ familyId: family.Titre, issueType: "Ex résistant.e.s without startResistant", }); } if (family.Sortie === null) { consistencyIssues.push({ familyId: family.Titre, issueType: "Ex résistant.e.s without endResistant", }); } if (family.Integration! > family.Sortie!) { consistencyIssues.push({ familyId: family.Titre, issueType: "startResistsant > endResistant ", }); } } consistencyIssues.push( ...family.Evenements.filter((e) => !isValidEvenementFamille(e.Type)).map( (e) => ({ familyId: family.Titre, 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, }) ) ); return consistencyIssues; }