mirror of
https://framagit.org/enfance-libre/statistiques
synced 2025-12-07 22:23:46 +00:00
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
|
|
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.status === "Résistant.e") {
|
||
|
|
if (family.startResistsant === null) {
|
||
|
|
consistencyIssues.push({
|
||
|
|
familyId: family.title,
|
||
|
|
issueType: "Résistant.e without startResistant",
|
||
|
|
});
|
||
|
|
}
|
||
|
|
if (family.endResistant !== null) {
|
||
|
|
consistencyIssues.push({
|
||
|
|
familyId: family.title,
|
||
|
|
issueType: "Résistant.e with endResistant!!",
|
||
|
|
});
|
||
|
|
}
|
||
|
|
} else if (family.status === "Ex résistant·e·s") {
|
||
|
|
if (family.startResistsant === null) {
|
||
|
|
consistencyIssues.push({
|
||
|
|
familyId: family.title,
|
||
|
|
issueType: "Ex résistant.e.s without startResistant",
|
||
|
|
});
|
||
|
|
}
|
||
|
|
if (family.endResistant === null) {
|
||
|
|
consistencyIssues.push({
|
||
|
|
familyId: family.title,
|
||
|
|
issueType: "Ex résistant.e.s without endResistant",
|
||
|
|
});
|
||
|
|
}
|
||
|
|
if (family.startResistsant!.getTime() > family.endResistant!.getTime()) {
|
||
|
|
consistencyIssues.push({
|
||
|
|
familyId: family.title,
|
||
|
|
issueType: "startResistsant > endResistant ",
|
||
|
|
});
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
if (family.startResistsant !== null) {
|
||
|
|
consistencyIssues.push({
|
||
|
|
familyId: family.title,
|
||
|
|
issueType: family.status + " with startResistant",
|
||
|
|
});
|
||
|
|
}
|
||
|
|
if (family.endResistant !== null) {
|
||
|
|
consistencyIssues.push({
|
||
|
|
familyId: family.title,
|
||
|
|
issueType: family.status + " with endResistant",
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return consistencyIssues;
|
||
|
|
}
|