2022-08-28 06:38:35 +02:00
|
|
|
import prisma from 'lib/prisma';
|
2022-11-08 07:35:51 +01:00
|
|
|
import cache from 'lib/cache';
|
2022-11-15 22:21:14 +01:00
|
|
|
import { Prisma, Website } from '@prisma/client';
|
2022-07-12 23:14:36 +02:00
|
|
|
|
2022-11-15 22:21:14 +01:00
|
|
|
export async function deleteWebsite(
|
|
|
|
websiteId: string,
|
|
|
|
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
|
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-11-10 07:46:50 +01:00
|
|
|
client.websiteEvent.deleteMany({
|
2022-11-15 22:21:14 +01:00
|
|
|
where: { websiteId },
|
2022-08-28 06:38:35 +02:00
|
|
|
}),
|
|
|
|
client.session.deleteMany({
|
2022-11-15 22:21:14 +01:00
|
|
|
where: { websiteId },
|
2022-08-28 06:38:35 +02:00
|
|
|
}),
|
|
|
|
client.website.delete({
|
2022-11-15 22:21:14 +01:00
|
|
|
where: { id: websiteId },
|
2022-08-28 06:38:35 +02:00
|
|
|
}),
|
2022-11-08 07:35:51 +01:00
|
|
|
]).then(async data => {
|
|
|
|
if (cache.enabled) {
|
2022-11-15 22:21:14 +01:00
|
|
|
await cache.deleteWebsite(websiteId);
|
2022-08-28 06:38:35 +02:00
|
|
|
}
|
2022-08-29 22:04:58 +02:00
|
|
|
|
2022-11-08 07:35:51 +01:00
|
|
|
return data;
|
2022-08-28 06:38:35 +02:00
|
|
|
});
|
2022-07-12 23:14:36 +02:00
|
|
|
}
|