diff --git a/src/dpe-sanitizer.service.js b/src/dpe-sanitizer.service.js index ed16983..7567624 100644 --- a/src/dpe-sanitizer.service.js +++ b/src/dpe-sanitizer.service.js @@ -53,7 +53,7 @@ export default class DpeSanitizerService { } if (this.#isEnum(key)) { - return val; + return val?.toString(); } if (this.#isUndefinedVal(val)) { diff --git a/src/engine.js b/src/engine.js index d748589..9118df8 100644 --- a/src/engine.js +++ b/src/engine.js @@ -19,6 +19,8 @@ import { collectionCanBeEmpty, containsAnySubstring, isEffetJoule, + use_enum_as_string, + useEnumAsString, xmlParser } from './utils.js'; import { Inertie } from './7_inertie.js'; @@ -66,7 +68,15 @@ export function calcul_3cl_xml(dpeXmlContent, options) { */ export function calcul_3cl(inputDpe, options) { if (!options) options = { sanitize: true }; - const dpe = options.sanitize ? dpeSanitizerService.execute(inputDpe) : inputDpe; + let dpe; + if (options.sanitize) { + dpe = dpeSanitizerService.execute(inputDpe); + } else { + dpe = inputDpe; + if (use_enum_as_string) { + useEnumAsString(inputDpe); + } + } const modele = enums.modele_dpe[dpe.administratif.enum_modele_dpe_id]; const dateDpe = dpe.administratif.date_etablissement_dpe; if (modele !== 'dpe 3cl 2021 méthode logement') { diff --git a/src/utils.js b/src/utils.js index 4ecfd87..d7439ca 100644 --- a/src/utils.js +++ b/src/utils.js @@ -39,6 +39,18 @@ export function set_bug_for_bug_compat() { bug_for_bug_compat = true; } +export function useEnumAsString(jsonObj) { + for (const key in jsonObj) { + if (jsonObj.hasOwnProperty(key)) { + if (key.startsWith('enum_')) { + if (jsonObj[key] !== null) jsonObj[key] = jsonObj[key].toString(); + } else if (typeof jsonObj[key] === 'object') { + useEnumAsString(jsonObj[key]); + } + } + } +} + export let use_enum_as_string = false; export function set_use_enum_as_string() { use_enum_as_string = true;