Allow several dossiers to share the same law

This commit is contained in:
Emmanuel 2023-03-06 13:25:46 +01:00
parent b252fd636e
commit 0865340cd7

View file

@ -17,7 +17,7 @@ async function associateDossiersLegislatifsWithAssemblee({
).map(({ id }) => id),
)
const dossierIdByLawId: { [nor: string]: string } = {}
const dossiersIdByLawId: { [nor: string]: Set<string> } = {}
const lawIdByNor: { [nor: string]: string } = {}
for (const dossier of (
await db<{ data: DossierLegislatif }[]>`
@ -63,7 +63,11 @@ async function associateDossiersLegislatifsWithAssemblee({
const nor = textelr.META.META_SPEC.META_TEXTE_CHRONICLE.NOR
assert.notStrictEqual(nor, undefined)
lawIdByNor[nor as string] = idTexte
dossierIdByLawId[idTexte] = dossier.META.META_COMMUN.ID
let lawDossiersId = dossiersIdByLawId[idTexte]
if (lawDossiersId === undefined) {
lawDossiersId = dossiersIdByLawId[idTexte] = new Set<string>()
}
dossiersIdByLawId[idTexte].add(dossier.META.META_COMMUN.ID)
}
}
if (lawsId.size === 0) {
@ -110,7 +114,7 @@ async function associateDossiersLegislatifsWithAssemblee({
continue
}
assert.notStrictEqual(lawId, undefined)
const dossierId = dossierIdByLawId[lawId]
for (const dossierId of dossiersIdByLawId[lawId]) {
assert.notStrictEqual(dossierId, undefined)
await db`
INSERT INTO dossier_legislatif_assemblee_associations (
@ -126,6 +130,7 @@ async function associateDossiersLegislatifsWithAssemblee({
`
dossierAssociationRemainingIds.delete(dossierId)
}
}
for (const id of dossierAssociationRemainingIds) {
console.log(