|
@ -32,9 +32,11 @@ export function nullifyValuesInObjects<T>(aObjects: T[], keys: string[]): T[] { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
export function redactAttributes({ |
|
|
export function redactAttributes({ |
|
|
|
|
|
isFirstRun = true, |
|
|
object, |
|
|
object, |
|
|
options |
|
|
options |
|
|
}: { |
|
|
}: { |
|
|
|
|
|
isFirstRun?: boolean; |
|
|
object: any; |
|
|
object: any; |
|
|
options: { attribute: string; valueMap: { [key: string]: any } }[]; |
|
|
options: { attribute: string; valueMap: { [key: string]: any } }[]; |
|
|
}): any { |
|
|
}): any { |
|
@ -42,7 +44,10 @@ export function redactAttributes({ |
|
|
return object; |
|
|
return object; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const redactedObject = cloneDeep(object); |
|
|
// Create deep clone
|
|
|
|
|
|
const redactedObject = isFirstRun |
|
|
|
|
|
? JSON.parse(JSON.stringify(object)) |
|
|
|
|
|
: object; |
|
|
|
|
|
|
|
|
for (const option of options) { |
|
|
for (const option of options) { |
|
|
if (redactedObject.hasOwnProperty(option.attribute)) { |
|
|
if (redactedObject.hasOwnProperty(option.attribute)) { |
|
@ -59,7 +64,11 @@ export function redactAttributes({ |
|
|
if (isArray(redactedObject[property])) { |
|
|
if (isArray(redactedObject[property])) { |
|
|
redactedObject[property] = redactedObject[property].map( |
|
|
redactedObject[property] = redactedObject[property].map( |
|
|
(currentObject) => { |
|
|
(currentObject) => { |
|
|
return redactAttributes({ options, object: currentObject }); |
|
|
return redactAttributes({ |
|
|
|
|
|
options, |
|
|
|
|
|
isFirstRun: false, |
|
|
|
|
|
object: currentObject |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
); |
|
|
); |
|
|
} else if ( |
|
|
} else if ( |
|
@ -69,6 +78,7 @@ export function redactAttributes({ |
|
|
// Recursively call the function on the nested object
|
|
|
// Recursively call the function on the nested object
|
|
|
redactedObject[property] = redactAttributes({ |
|
|
redactedObject[property] = redactAttributes({ |
|
|
options, |
|
|
options, |
|
|
|
|
|
isFirstRun: false, |
|
|
object: redactedObject[property] |
|
|
object: redactedObject[property] |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|