This commit is contained in:
daniel31x13
2024-08-18 16:39:43 -04:00
parent 2b83522eaa
commit 1260e8c093
10 changed files with 268 additions and 272 deletions
@@ -22,32 +22,5 @@ export default async function exportData(userId: number) {
const { password, id, ...userData } = user;
function redactIds(data: object | object[]): void {
if (Array.isArray(data)) {
data.forEach((item) => redactIds(item));
} else if (data !== null && typeof data === "object") {
const fieldsToRedact = ["id", "parentId", "collectionId", "ownerId"];
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);
}
});
}
}
redactIds(userData);
return { response: userData, status: 200 };
}