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