Skip to content

Commit bb583ee

Browse files
Merge pull request #168 from Open3CL/fix_issue_sanitizing
fix: saniting issue - missing element collection created if missing
2 parents 76da104 + 7622579 commit bb583ee

3 files changed

Lines changed: 1517 additions & 8 deletions

File tree

src/dpe-sanitizer.service.js

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
11
import { ObjectUtil } from './core/util/infrastructure/object-util.js';
2+
import { set, has } from 'lodash-es';
23

34
const nodesToMap = [
4-
'mur',
5-
'plancher_bas',
6-
'plancher_haut',
7-
'baie_vitree',
8-
'porte',
9-
'pont_thermique',
10-
'ventilation',
115
'installation_ecs',
126
'generateur_ecs',
13-
'climatisation',
147
'installation_chauffage',
158
'generateur_chauffage',
169
'emetteur_chauffage',
1710
'sortie_par_energie'
1811
];
1912

13+
const nodesCollectionToCheck = [
14+
'logement.enveloppe.mur_collection.mur',
15+
'logement.enveloppe.plancher_bas_collection.plancher_bas',
16+
'logement.enveloppe.plancher_haut_collection.plancher_haut',
17+
'logement.ventilation_collection.ventilation',
18+
'logement.climatisation_collection.climatisation',
19+
'logement.enveloppe.baie_vitree_collection.baie_vitree',
20+
'logement.enveloppe.porte_collection.porte',
21+
'logement.enveloppe.pont_thermique_collection.pont_thermique'
22+
];
23+
2024
/**
2125
* Transform single nodes in {@link nodesToMap} into array of nodes.
2226
* Transform string number into digits
2327
* These transformations should be done inside the open3cl library
2428
*
2529
* @example
30+
*
31+
* // Will create
32+
* "plancher_haut_collection": {
33+
* "plancher_haut": []
34+
* }
35+
* if the plancher_haut_collection.plancher_haut nodes does not exist or are not an array
36+
*
2637
* // Will transform
2738
* "plancher_haut_collection": {
2839
* "plancher_haut": {"id": 1}
@@ -44,6 +55,12 @@ export default class DpeSanitizerService {
4455
* @return {FullDpe}
4556
*/
4657
execute(dpe) {
58+
for (const path of nodesCollectionToCheck) {
59+
if (!has(dpe, path)) {
60+
set(dpe, path, []);
61+
}
62+
}
63+
4764
return ObjectUtil.deepObjectTransform(
4865
dpe,
4966
(key) => key,

0 commit comments

Comments
 (0)