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