This commit is contained in:
parent
8b46bf354e
commit
d9e9824146
@ -39,6 +39,21 @@ export async function savePostServer(
|
|||||||
const slug = slugify(title, { lower: true, strict: true });
|
const slug = slugify(title, { lower: true, strict: true });
|
||||||
|
|
||||||
if (existingSlug) {
|
if (existingSlug) {
|
||||||
|
const post = await prisma.post.findUnique({
|
||||||
|
where: { slug: existingSlug },
|
||||||
|
include: { tags: true },
|
||||||
|
});
|
||||||
|
if (!post) {
|
||||||
|
throw new Error("Post not found");
|
||||||
|
}
|
||||||
|
for (const tag of post.tags) {
|
||||||
|
const postsWithTag = await prisma.post.count({
|
||||||
|
where: { tags: { some: { id: tag.id } } },
|
||||||
|
});
|
||||||
|
if (postsWithTag == 0) {
|
||||||
|
await prisma.tag.delete({ where: { id: tag.id } });
|
||||||
|
}
|
||||||
|
}
|
||||||
await prisma.post.delete({ where: { slug: existingSlug } });
|
await prisma.post.delete({ where: { slug: existingSlug } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user