import { Family } from "./Family"; export function checkDataConsistency(families: Family[]): ConsistencyIssue[] { return families.flatMap((family) => { return checkFamilyDataConsistency(family); }); } export type ConsistencyIssue = { issueType: string; familyId: string; }; function checkFamilyDataConsistency(family: Family) { 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!.getTime() > family.Sortie!.getTime()) { consistencyIssues.push({ familyId: family.Titre, issueType: "startResistsant > endResistant ", }); } } else { if (family.Integration !== null) { consistencyIssues.push({ familyId: family.Titre, issueType: family.Statut + " with startResistant", }); } if (family.Sortie !== null) { consistencyIssues.push({ familyId: family.Titre, issueType: family.Statut + " with endResistant", }); } } return consistencyIssues; }