This commit is contained in:
		| @@ -39,6 +39,21 @@ export async function savePostServer( | ||||
|   const slug = slugify(title, { lower: true, strict: true }); | ||||
|  | ||||
|   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 } }); | ||||
|   } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user