umami/queries/admin/website/deleteWebsite.js

31 lines
650 B
JavaScript
Raw Normal View History

2022-08-28 06:38:35 +02:00
import prisma from 'lib/prisma';
import cache from 'lib/cache';
2022-07-12 23:14:36 +02:00
2022-11-01 07:42:37 +01:00
export async function deleteWebsite(id) {
2022-08-29 09:02:38 +02:00
const { client, transaction } = prisma;
2022-08-28 06:38:35 +02:00
2022-08-29 09:02:38 +02:00
return transaction([
2022-08-28 06:38:35 +02:00
client.pageview.deleteMany({
2022-11-08 20:55:02 +01:00
where: { websiteId: id },
2022-08-28 06:38:35 +02:00
}),
client.eventData.deleteMany({
2022-11-08 20:55:02 +01:00
where: { event: { websiteId: id } },
2022-08-28 06:38:35 +02:00
}),
client.event.deleteMany({
2022-11-08 20:55:02 +01:00
where: { websiteId: id },
2022-08-28 06:38:35 +02:00
}),
client.session.deleteMany({
2022-11-08 20:55:02 +01:00
where: { websiteId: id },
2022-08-28 06:38:35 +02:00
}),
client.website.delete({
2022-11-01 07:42:37 +01:00
where: { id },
2022-08-28 06:38:35 +02:00
}),
]).then(async data => {
if (cache.enabled) {
await cache.deleteWebsite(id);
2022-08-28 06:38:35 +02:00
}
2022-08-29 22:04:58 +02:00
return data;
2022-08-28 06:38:35 +02:00
});
2022-07-12 23:14:36 +02:00
}