Improve structure of échéancier

This commit is contained in:
Emmanuel 2023-02-06 16:07:23 +01:00
parent d8b8b84942
commit 23edd79999
3 changed files with 23 additions and 13 deletions

View file

@ -12,6 +12,7 @@ import {
auditSwitch,
auditString,
auditTest,
auditNumber,
} from "@auditors/core"
function auditContenu(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
@ -177,7 +178,23 @@ function auditLigne(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
const errors: { [key: string]: unknown } = {}
const remainingKeys = new Set(Object.keys(data))
for (const key of ["ARTICLE", "BASE_LEGALE", "DECRET", "OBJET"]) {
audit.attribute(
data,
"ARTICLE",
true,
errors,
remainingKeys,
auditSwitch(
[
auditNumber,
auditInteger,
auditFunction((article) => article.toString()),
],
auditTrimString,
),
auditEmptyToNull,
)
for (const key of ["BASE_LEGALE", "DECRET", "OBJET"]) {
audit.attribute(
data,
key,
@ -224,15 +241,10 @@ function auditLigne(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
errors,
remainingKeys,
auditSwitch(
[auditInteger, auditFunction((numero) => [numero])],
[
auditString,
auditFunction((numeros) => numeros.split(",")),
auditArray(auditStringToNumber, auditInteger),
],
[auditNumber, auditInteger, auditFunction((numero) => numero.toString())],
auditTrimString,
),
auditArray(auditRequire),
auditRequire,
auditEmptyToNull,
)
return audit.reduceRemaining(data, errors, remainingKeys)

View file

@ -216,7 +216,7 @@ export interface Ligne {
"@id": string // Always a JORFARTI ID
"#text": string
}>
NUMERO_ORDRE: number[]
NUMERO_ORDRE?: string
OBJET?: string
}

View file

@ -47,9 +47,7 @@ async function exportEcheanciers(csvFilePath: string): Promise<void> {
lien_article_texte: lienArticle["#text"],
derniere_maj: echeancier["@derniere_maj"],
id: dossierLegislatif.META.META_COMMUN.ID,
numero_ordre: ligne.NUMERO_ORDRE.map((numero) =>
numero.toString(),
).join(", "),
numero_ordre: ligne.NUMERO_ORDRE,
objet: ligne.OBJET,
titre: dossierLegislatif.META.META_DOSSIER_LEGISLATIF.TITRE,
})