2022-08-28 06:38:35 +02:00
|
|
|
import prisma from 'lib/prisma';
|
2022-08-29 22:04:58 +02:00
|
|
|
import redis, { DELETED } from 'lib/redis';
|
2022-07-12 23:14:36 +02:00
|
|
|
|
2022-10-25 19:45:56 +02:00
|
|
|
export async function deleteWebsite(websiteUuid) {
|
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-10-25 19:45:56 +02:00
|
|
|
where: { session: { website: { websiteUuid } } },
|
2022-08-28 06:38:35 +02:00
|
|
|
}),
|
2022-10-10 22:42:18 +02:00
|
|
|
client.eventData.deleteMany({
|
2022-10-25 19:45:56 +02:00
|
|
|
where: { event: { session: { website: { websiteUuid } } } },
|
2022-08-28 06:38:35 +02:00
|
|
|
}),
|
|
|
|
client.event.deleteMany({
|
2022-10-25 19:45:56 +02:00
|
|
|
where: { session: { website: { websiteUuid } } },
|
2022-08-28 06:38:35 +02:00
|
|
|
}),
|
|
|
|
client.session.deleteMany({
|
2022-10-25 19:45:56 +02:00
|
|
|
where: { website: { websiteUuid } },
|
2022-08-28 06:38:35 +02:00
|
|
|
}),
|
|
|
|
client.website.delete({
|
2022-10-25 19:45:56 +02:00
|
|
|
where: { websiteUuid },
|
2022-08-28 06:38:35 +02:00
|
|
|
}),
|
|
|
|
]).then(async res => {
|
2022-08-29 22:04:58 +02:00
|
|
|
if (redis.client) {
|
2022-10-10 22:42:18 +02:00
|
|
|
await redis.client.set(`website:${websiteUuid}`, DELETED);
|
2022-08-28 06:38:35 +02:00
|
|
|
}
|
2022-08-29 22:04:58 +02:00
|
|
|
|
|
|
|
return res;
|
2022-08-28 06:38:35 +02:00
|
|
|
});
|
2022-07-12 23:14:36 +02:00
|
|
|
}
|