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, auditSwitch,
auditString, auditString,
auditTest, auditTest,
auditNumber,
} from "@auditors/core" } from "@auditors/core"
function auditContenu(audit: Audit, dataUnknown: unknown): [unknown, unknown] { 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 errors: { [key: string]: unknown } = {}
const remainingKeys = new Set(Object.keys(data)) 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( audit.attribute(
data, data,
key, key,
@ -224,15 +241,10 @@ function auditLigne(audit: Audit, dataUnknown: unknown): [unknown, unknown] {
errors, errors,
remainingKeys, remainingKeys,
auditSwitch( auditSwitch(
[auditInteger, auditFunction((numero) => [numero])], [auditNumber, auditInteger, auditFunction((numero) => numero.toString())],
[ auditTrimString,
auditString,
auditFunction((numeros) => numeros.split(",")),
auditArray(auditStringToNumber, auditInteger),
],
), ),
auditArray(auditRequire), auditEmptyToNull,
auditRequire,
) )
return audit.reduceRemaining(data, errors, remainingKeys) return audit.reduceRemaining(data, errors, remainingKeys)

View file

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

View file

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