mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-16 02:05:04 +01:00
46 lines
1.0 KiB
JavaScript
46 lines
1.0 KiB
JavaScript
import prisma from 'lib/prisma';
|
|
import cache from 'lib/cache';
|
|
|
|
export async function deleteUser(userId) {
|
|
const { client } = prisma;
|
|
|
|
const websites = await client.website.findMany({
|
|
where: { userId },
|
|
});
|
|
|
|
return client
|
|
.$transaction([
|
|
client.pageview.deleteMany({
|
|
where: { session: { website: { userId } } },
|
|
}),
|
|
client.eventData.deleteMany({
|
|
where: { event: { session: { website: { userId } } } },
|
|
}),
|
|
client.event.deleteMany({
|
|
where: { session: { website: { userId } } },
|
|
}),
|
|
client.session.deleteMany({
|
|
where: { website: { userId } },
|
|
}),
|
|
client.website.deleteMany({
|
|
where: { userId },
|
|
}),
|
|
client.user.delete({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
}),
|
|
])
|
|
.then(async data => {
|
|
if (cache.enabled) {
|
|
const ids = websites.map(a => a.id);
|
|
|
|
for (let i = 0; i < ids.length; i++) {
|
|
await cache.deleteWebsite(`website:${ids[i]}`);
|
|
}
|
|
}
|
|
|
|
return data;
|
|
});
|
|
}
|