Add animal bool to tags

This commit is contained in:
2025-12-21 16:47:19 +01:00
parent d7163c4019
commit d1adb07f40
12 changed files with 190 additions and 8 deletions

View File

@ -0,0 +1,37 @@
"use server";
import { prisma } from "@/lib/prisma";
import { revalidatePath } from "next/cache";
export async function deleteCategory(catId: string) {
const cat = await prisma.artCategory.findUnique({
where: { id: catId },
select: {
id: true,
_count: {
select: {
tags: true,
artworks: true
},
},
},
});
if (!cat) {
throw new Error("Category not found.");
}
if (cat._count.artworks > 0) {
throw new Error("Cannot delete category: it is used by artworks.");
}
if (cat._count.tags > 0) {
throw new Error("Cannot delete category: it is used by tags.");
}
await prisma.artCategory.delete({ where: { id: catId } });
revalidatePath("/categories");
return { success: true };
}

View File

@ -22,6 +22,7 @@ export async function createTag(formData: TagFormInput) {
name: data.name,
slug: tagSlug,
description: data.description,
showOnAnimalPage: data.showOnAnimalPage,
parentId
},
});

View File

@ -32,7 +32,8 @@ export async function updateTag(id: string, rawData: TagFormInput) {
data: {
name: data.name,
slug: tagSlug,
description: data.description,
description: data.description,
showOnAnimalPage: data.showOnAnimalPage,
parentId,
categories: data.categoryIds
? { set: data.categoryIds.map((cid) => ({ id: cid })) }