diff --git a/src/lib/auditors/dole.ts b/src/lib/auditors/dole.ts index e3064d2..337495b 100644 --- a/src/lib/auditors/dole.ts +++ b/src/lib/auditors/dole.ts @@ -321,7 +321,7 @@ function auditLegislature( return audit.unexpectedType(dataUnknown, "object") } - const data = { ...dataUnknown } + const data: { [key: string]: unknown } = { ...dataUnknown } const errors: { [key: string]: unknown } = {} const remainingKeys = new Set(Object.keys(data)) @@ -332,8 +332,9 @@ function auditLegislature( true, errors, remainingKeys, + auditTrimString, + auditEmptyToNull, auditDateIso8601String, - auditRequire, ) } audit.attribute( @@ -344,7 +345,6 @@ function auditLegislature( remainingKeys, auditTrimString, auditEmptyToNull, - auditRequire, ) audit.attribute( data, @@ -352,10 +352,29 @@ function auditLegislature( true, errors, remainingKeys, - auditInteger, - auditRequire, + auditSwitch(auditInteger, [ + auditTrimString, + auditEmptyToNull, + auditNullish, + ]), ) + if ( + Object.keys(errors).length === 0 && + data.DATE_DEBUT == null && + data.DATE_FIN == null && + data.LIBELLE == null && + data.NUMERO == null + ) { + return [null, null] + } + + for (const key of ["DATE_DEBUT", "DATE_FIN", "LIBELLE", "NUMERO"]) { + if (errors[key] !== undefined) { + audit.attribute(data, key, true, errors, remainingKeys, auditRequire) + } + } + return audit.reduceRemaining(data, errors, remainingKeys) } @@ -627,7 +646,6 @@ function auditMetaDossierLegislatif( errors, remainingKeys, auditLegislature, - auditRequire, ) audit.attribute( data, diff --git a/src/lib/legal/dole.ts b/src/lib/legal/dole.ts index 3464146..d208e99 100644 --- a/src/lib/legal/dole.ts +++ b/src/lib/legal/dole.ts @@ -48,7 +48,7 @@ export interface DossierLegislatif { ID_TEXTE_3?: string // Always starts with JORFTEXT when present ID_TEXTE_4?: string // Always starts with JORFTEXT when present ID_TEXTE_5?: string // Always starts with JORFTEXT when present - LEGISLATURE: { + LEGISLATURE?: { DATE_DEBUT: string DATE_FIN: string LIBELLE: string