Skip to content
Snippets Groups Projects
Commit 1a3a43cb authored by David Smadja's avatar David Smadja
Browse files

Add variable exclusion

parent ea7be976
No related branches found
No related tags found
No related merge requests found
Pipeline #19875 passed
...@@ -164,13 +164,13 @@ function replaceValuesFromReplacedKeys( ...@@ -164,13 +164,13 @@ function replaceValuesFromReplacedKeys(
return newObj return newObj
} }
function removeZeroValues(obj: any): any { function removeZeroValuesAndExcludedVariables(obj: any): any {
if (typeof obj !== "object" || obj === null) { if (typeof obj !== "object" || obj === null) {
return obj return obj
} }
if (Array.isArray(obj)) { if (Array.isArray(obj)) {
return obj.map(removeZeroValues) return obj.map(removeZeroValuesAndExcludedVariables)
} }
const newObj: any = {} const newObj: any = {}
...@@ -180,11 +180,14 @@ function removeZeroValues(obj: any): any { ...@@ -180,11 +180,14 @@ function removeZeroValues(obj: any): any {
const value = obj[key] const value = obj[key]
if (typeof value === "object" && value !== null) { if (typeof value === "object" && value !== null) {
if (Object.values(value).every((v) => v === 0 || v === null)) { if (
Object.values(value).every((v) => v === 0 || v === null) ||
key === "prelevements_sociaux_menage"
) {
continue continue
} }
const cleanedValue = removeZeroValues(value) const cleanedValue = removeZeroValuesAndExcludedVariables(value)
if (Object.keys(cleanedValue).length > 0) { if (Object.keys(cleanedValue).length > 0) {
newObj[key] = cleanedValue newObj[key] = cleanedValue
} }
...@@ -205,7 +208,7 @@ function cleanSimulatedJson(jsonData: any): any { ...@@ -205,7 +208,7 @@ function cleanSimulatedJson(jsonData: any): any {
jsonData[section] = Object.fromEntries( jsonData[section] = Object.fromEntries(
Object.entries(jsonData[section]).map(([key, value]) => [ Object.entries(jsonData[section]).map(([key, value]) => [
key, key,
removeZeroValues(value), removeZeroValuesAndExcludedVariables(value),
]), ]),
) )
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment