mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
34 lines
889 B
JavaScript
34 lines
889 B
JavaScript
import prisma from 'lib/prisma';
|
|
import redis, { DELETED } from 'lib/redis';
|
|
import { getWebsiteById } from 'queries';
|
|
|
|
export async function deleteWebsite(website_id) {
|
|
const { client, transaction } = prisma;
|
|
|
|
const { website_uuid } = await getWebsiteById(website_id);
|
|
|
|
return transaction([
|
|
client.pageview.deleteMany({
|
|
where: { session: { website: { website_id } } },
|
|
}),
|
|
client.event_data.deleteMany({
|
|
where: { event: { session: { website: { website_id } } } },
|
|
}),
|
|
client.event.deleteMany({
|
|
where: { session: { website: { website_id } } },
|
|
}),
|
|
client.session.deleteMany({
|
|
where: { website: { website_id } },
|
|
}),
|
|
client.website.delete({
|
|
where: { website_id },
|
|
}),
|
|
]).then(async res => {
|
|
if (redis.client) {
|
|
await redis.client.set(`website:${website_uuid}`, DELETED);
|
|
}
|
|
|
|
return res;
|
|
});
|
|
}
|