Allow several dossiers to share the same law
This commit is contained in:
parent
b252fd636e
commit
0865340cd7
1 changed files with 22 additions and 17 deletions
|
@ -17,7 +17,7 @@ async function associateDossiersLegislatifsWithAssemblee({
|
||||||
).map(({ id }) => id),
|
).map(({ id }) => id),
|
||||||
)
|
)
|
||||||
|
|
||||||
const dossierIdByLawId: { [nor: string]: string } = {}
|
const dossiersIdByLawId: { [nor: string]: Set<string> } = {}
|
||||||
const lawIdByNor: { [nor: string]: string } = {}
|
const lawIdByNor: { [nor: string]: string } = {}
|
||||||
for (const dossier of (
|
for (const dossier of (
|
||||||
await db<{ data: DossierLegislatif }[]>`
|
await db<{ data: DossierLegislatif }[]>`
|
||||||
|
@ -63,7 +63,11 @@ async function associateDossiersLegislatifsWithAssemblee({
|
||||||
const nor = textelr.META.META_SPEC.META_TEXTE_CHRONICLE.NOR
|
const nor = textelr.META.META_SPEC.META_TEXTE_CHRONICLE.NOR
|
||||||
assert.notStrictEqual(nor, undefined)
|
assert.notStrictEqual(nor, undefined)
|
||||||
lawIdByNor[nor as string] = idTexte
|
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) {
|
if (lawsId.size === 0) {
|
||||||
|
@ -110,21 +114,22 @@ async function associateDossiersLegislatifsWithAssemblee({
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
assert.notStrictEqual(lawId, undefined)
|
assert.notStrictEqual(lawId, undefined)
|
||||||
const dossierId = dossierIdByLawId[lawId]
|
for (const dossierId of dossiersIdByLawId[lawId]) {
|
||||||
assert.notStrictEqual(dossierId, undefined)
|
assert.notStrictEqual(dossierId, undefined)
|
||||||
await db`
|
await db`
|
||||||
INSERT INTO dossier_legislatif_assemblee_associations (
|
INSERT INTO dossier_legislatif_assemblee_associations (
|
||||||
id,
|
id,
|
||||||
assemblee_uid
|
assemblee_uid
|
||||||
) VALUES (
|
) VALUES (
|
||||||
${dossierId},
|
${dossierId},
|
||||||
${assembleeDossier.uid}
|
${assembleeDossier.uid}
|
||||||
)
|
)
|
||||||
ON CONFLICT (id)
|
ON CONFLICT (id)
|
||||||
DO UPDATE SET
|
DO UPDATE SET
|
||||||
assemblee_uid = ${assembleeDossier.uid}
|
assemblee_uid = ${assembleeDossier.uid}
|
||||||
`
|
`
|
||||||
dossierAssociationRemainingIds.delete(dossierId)
|
dossierAssociationRemainingIds.delete(dossierId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const id of dossierAssociationRemainingIds) {
|
for (const id of dossierAssociationRemainingIds) {
|
||||||
|
|
Loading…
Reference in a new issue