2024-06-05 21:35:55 +02:00
|
|
|
import { isValidEvenementFamille } from "./EvenementFamille";
|
2024-06-03 21:56:35 +02:00
|
|
|
import { Famille } from "./Famille";
|
2024-06-02 14:34:11 +02:00
|
|
|
|
2024-06-03 21:56:35 +02:00
|
|
|
export function checkDataConsistency(families: Famille[]): ConsistencyIssue[] {
|
2024-06-02 14:34:11 +02:00
|
|
|
return families.flatMap((family) => {
|
|
|
|
|
return checkFamilyDataConsistency(family);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type ConsistencyIssue = {
|
|
|
|
|
issueType: string;
|
|
|
|
|
familyId: string;
|
2024-06-06 21:48:10 +02:00
|
|
|
canIgnore?: boolean;
|
2024-06-02 14:34:11 +02:00
|
|
|
};
|
2024-06-03 21:56:35 +02:00
|
|
|
function checkFamilyDataConsistency(family: Famille) {
|
2024-06-02 14:34:11 +02:00
|
|
|
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-04 21:55:38 +02:00
|
|
|
if (family.Integration! > family.Sortie!) {
|
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 ",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-05 21:35:55 +02:00
|
|
|
consistencyIssues.push(
|
|
|
|
|
...family.Evenements.filter((e) => !isValidEvenementFamille(e.Type)).map(
|
|
|
|
|
(e) => ({
|
|
|
|
|
familyId: family.Titre,
|
2024-06-06 21:48:10 +02:00
|
|
|
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,
|
2024-06-05 21:35:55 +02:00
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
);
|
2024-06-02 14:34:11 +02:00
|
|
|
return consistencyIssues;
|
|
|
|
|
}
|