Redact all ids when exporting data
This commit is contained in:
parent
0b8a9b4310
commit
02cb93065f
|
@ -22,14 +22,25 @@ export default async function exportData(userId: number) {
|
||||||
|
|
||||||
const { password, id, ...userData } = user;
|
const { password, id, ...userData } = user;
|
||||||
|
|
||||||
function redactIds(obj: any) {
|
function redactIds(data: object | object[]): void {
|
||||||
if (Array.isArray(obj)) {
|
if (Array.isArray(data)) {
|
||||||
obj.forEach((o) => redactIds(o));
|
data.forEach((item) => redactIds(item));
|
||||||
} else if (obj !== null && typeof obj === "object") {
|
} else if (data !== null && typeof data === "object") {
|
||||||
delete obj.id;
|
const fieldsToRedact = ['id', 'parentId', 'collectionId', 'ownerId'];
|
||||||
for (let key in obj) {
|
|
||||||
redactIds(obj[key]);
|
fieldsToRedact.forEach((field) => {
|
||||||
}
|
if (field in data) {
|
||||||
|
delete (data as any)[field];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Recursively call redactIds for each property that is an object or an array
|
||||||
|
Object.keys(data).forEach((key) => {
|
||||||
|
const value = (data as any)[key];
|
||||||
|
if (value !== null && (typeof value === "object" || Array.isArray(value))) {
|
||||||
|
redactIds(value);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue