@tricoteuses/senat 2.20.25 → 2.20.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -73,6 +73,8 @@ function detectLecture(objet) {
|
|
|
73
73
|
return undefined;
|
|
74
74
|
}
|
|
75
75
|
function computeCodeEtape(ev, dossier) {
|
|
76
|
+
// In order to match with etape, we need to remove the '-SEANCE' suffix from the codeActe
|
|
77
|
+
const cleanCode = (code) => code.replace(/-SEANCE$/, "");
|
|
76
78
|
const lecture = detectLecture(ev.objet ?? "");
|
|
77
79
|
const organe = ev.organe ?? "";
|
|
78
80
|
const nature = organe.toLowerCase().includes("commission")
|
|
@@ -82,7 +84,7 @@ function computeCodeEtape(ev, dossier) {
|
|
|
82
84
|
: "";
|
|
83
85
|
const evDate = ev.date.split("T")[0];
|
|
84
86
|
const flat = buildFlatActes(dossier);
|
|
85
|
-
// 1)
|
|
87
|
+
// 1) Strict matching : same date + nature
|
|
86
88
|
let candidates = flat.filter((a) => {
|
|
87
89
|
if (a.date !== evDate)
|
|
88
90
|
return false;
|
|
@@ -90,47 +92,39 @@ function computeCodeEtape(ev, dossier) {
|
|
|
90
92
|
return false;
|
|
91
93
|
return true;
|
|
92
94
|
});
|
|
93
|
-
//
|
|
94
|
-
// candidates.forEach((c) => console.log(` STRICT MATCH: ${c.codeActe} (date=${c.date}, lecture=${c.ordreLecture})`))
|
|
95
|
-
// Si lecture détectée → on filtre si ça garde des candidats
|
|
95
|
+
// If lecture is specified, filter by it
|
|
96
96
|
if (lecture !== undefined && candidates.length > 0) {
|
|
97
97
|
const withLecture = candidates.filter((c) => c.ordreLecture === lecture);
|
|
98
98
|
if (withLecture.length > 0) {
|
|
99
|
-
// console.log(` → filtre lecture=${lecture} : ${withLecture.length} candidats`)
|
|
100
99
|
candidates = withLecture;
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
102
|
// Multiple candidates : we take the longest ?
|
|
104
103
|
if (candidates.length > 0) {
|
|
105
104
|
candidates.sort((a, b) => b.codeActe.length - a.codeActe.length);
|
|
106
|
-
|
|
107
|
-
return candidates[0].codeActe;
|
|
105
|
+
return cleanCode(candidates[0].codeActe);
|
|
108
106
|
}
|
|
109
|
-
// 2) fallback COM
|
|
107
|
+
// 2) fallback COM
|
|
110
108
|
if (nature === "COM") {
|
|
111
109
|
let comActs = flat.filter((a) => a.codeActe.includes("COM") && a.date <= evDate);
|
|
112
|
-
// console.log(` → fallback COM: actes COM <= date : ${comActs.length}`)
|
|
113
110
|
if (lecture !== undefined) {
|
|
114
111
|
const byLecture = comActs.filter((a) => a.ordreLecture === lecture);
|
|
115
112
|
if (byLecture.length > 0) {
|
|
116
113
|
comActs = byLecture;
|
|
117
|
-
// console.log(` → filtrés lecture=${lecture}: ${comActs.length}`)
|
|
118
114
|
}
|
|
119
115
|
}
|
|
120
116
|
if (comActs.length > 0) {
|
|
121
117
|
comActs.sort((a, b) => b.date.localeCompare(a.date) || b.codeActe.length - a.codeActe.length);
|
|
122
|
-
|
|
123
|
-
return comActs[0].codeActe;
|
|
118
|
+
return cleanCode(comActs[0].codeActe);
|
|
124
119
|
}
|
|
125
120
|
}
|
|
126
|
-
// 3) Fallback lecture générale
|
|
121
|
+
// 3) Fallback lecture générale
|
|
127
122
|
if (lecture !== undefined) {
|
|
128
123
|
const lectures = dossier["actes_legislatifs"] ?? [];
|
|
129
124
|
const lectureNode = lectures.find((l) => l.ordre_lecture === lecture);
|
|
130
125
|
const rootCode = lectureNode?.code_acte;
|
|
131
126
|
if (rootCode && typeof rootCode === "string") {
|
|
132
|
-
|
|
133
|
-
return rootCode;
|
|
127
|
+
return cleanCode(rootCode);
|
|
134
128
|
}
|
|
135
129
|
}
|
|
136
130
|
console.log(` ✖ aucun code d’étape trouvé pour ev=${ev.id}`);
|