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

26 lines
677 B
JavaScript

import prisma from 'lib/prisma';
import redis from 'lib/redis';
export async function resetWebsite(website_id) {
const { client, transaction } = prisma;
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 } },
}),
]).then(async res => {
if (redis.client) {
await redis.del(`website:${res.website_uuid}`);
}
});
}