mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
78338205a3
* checkpoint * fix pg schema * fix mysql schema * change property names
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
import prisma from 'lib/prisma';
|
|
import redis, { DELETED } from 'lib/redis';
|
|
|
|
export async function deleteAccount(userId) {
|
|
const { client } = prisma;
|
|
|
|
const websites = await client.website.findMany({
|
|
where: { userId },
|
|
select: { websiteUuid: true },
|
|
});
|
|
|
|
let websiteUuids = [];
|
|
|
|
if (websites.length > 0) {
|
|
websiteUuids = websites.map(a => a.websiteUuid);
|
|
}
|
|
|
|
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.account.delete({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
}),
|
|
])
|
|
.then(async res => {
|
|
if (redis.client) {
|
|
for (let i = 0; i < websiteUuids.length; i++) {
|
|
await redis.set(`website:${websiteUuids[i]}`, DELETED);
|
|
}
|
|
}
|
|
|
|
return res;
|
|
});
|
|
}
|