el.xwx.moe/lib/api/controllers/migration/exportData.ts

38 lines
802 B
TypeScript
Raw Normal View History

import { prisma } from "@/lib/api/db";
export default async function exportData(userId: number) {
const user = await prisma.user.findUnique({
where: { id: userId },
include: {
collections: {
include: {
links: {
include: {
tags: true,
},
},
},
},
},
});
if (!user) return { response: "User not found.", status: 404 };
2023-10-26 17:49:46 -05:00
const { password, id, ...userData } = user;
2023-10-16 17:27:04 -05:00
function redactIds(obj: any) {
if (Array.isArray(obj)) {
obj.forEach((o) => redactIds(o));
} else if (obj !== null && typeof obj === "object") {
delete obj.id;
for (let key in obj) {
redactIds(obj[key]);
}
}
}
redactIds(userData);
return { response: userData, status: 200 };
}