umami/queries/admin/website/deleteWebsite.js
2022-08-29 13:04:58 -07:00

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;
});
}