2024-06-02 14:34:11 +02:00
|
|
|
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[] = [];
|
|
|
|
|
|
2024-06-02 21:00:42 +02:00
|
|
|
if (family.Statut === "Résistant.e") {
|
|
|
|
|
if (family.Integration === null) {
|
2024-06-02 14:34:11 +02:00
|
|
|
consistencyIssues.push({
|
2024-06-02 21:00:42 +02:00
|
|
|
familyId: family.Titre,
|
2024-06-02 14:34:11 +02:00
|
|
|
issueType: "Résistant.e without startResistant",
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-06-02 21:00:42 +02:00
|
|
|
if (family.Sortie !== null) {
|
2024-06-02 14:34:11 +02:00
|
|
|
consistencyIssues.push({
|
2024-06-02 21:00:42 +02:00
|
|
|
familyId: family.Titre,
|
2024-06-02 14:34:11 +02:00
|
|
|
issueType: "Résistant.e with endResistant!!",
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-06-02 21:00:42 +02:00
|
|
|
} else if (family.Statut === "Ex résistant·e·s") {
|
|
|
|
|
if (family.Integration === null) {
|
2024-06-02 14:34:11 +02:00
|
|
|
consistencyIssues.push({
|
2024-06-02 21:00:42 +02:00
|
|
|
familyId: family.Titre,
|
2024-06-02 14:34:11 +02:00
|
|
|
issueType: "Ex résistant.e.s without startResistant",
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-06-02 21:00:42 +02:00
|
|
|
if (family.Sortie === null) {
|
2024-06-02 14:34:11 +02:00
|
|
|
consistencyIssues.push({
|
2024-06-02 21:00:42 +02:00
|
|
|
familyId: family.Titre,
|
2024-06-02 14:34:11 +02:00
|
|
|
issueType: "Ex résistant.e.s without endResistant",
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-06-02 21:00:42 +02:00
|
|
|
if (family.Integration!.getTime() > family.Sortie!.getTime()) {
|
2024-06-02 14:34:11 +02:00
|
|
|
consistencyIssues.push({
|
2024-06-02 21:00:42 +02:00
|
|
|
familyId: family.Titre,
|
2024-06-02 14:34:11 +02:00
|
|
|
issueType: "startResistsant > endResistant ",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-06-02 21:00:42 +02:00
|
|
|
if (family.Integration !== null) {
|
2024-06-02 14:34:11 +02:00
|
|
|
consistencyIssues.push({
|
2024-06-02 21:00:42 +02:00
|
|
|
familyId: family.Titre,
|
|
|
|
|
issueType: family.Statut + " with startResistant",
|
2024-06-02 14:34:11 +02:00
|
|
|
});
|
|
|
|
|
}
|
2024-06-02 21:00:42 +02:00
|
|
|
if (family.Sortie !== null) {
|
2024-06-02 14:34:11 +02:00
|
|
|
consistencyIssues.push({
|
2024-06-02 21:00:42 +02:00
|
|
|
familyId: family.Titre,
|
|
|
|
|
issueType: family.Statut + " with endResistant",
|
2024-06-02 14:34:11 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return consistencyIssues;
|
|
|
|
|
}
|