Add animal bool to tags
This commit is contained in:
37
src/actions/categories/deleteCategory.ts
Normal file
37
src/actions/categories/deleteCategory.ts
Normal 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 };
|
||||
}
|
||||
@ -22,6 +22,7 @@ export async function createTag(formData: TagFormInput) {
|
||||
name: data.name,
|
||||
slug: tagSlug,
|
||||
description: data.description,
|
||||
showOnAnimalPage: data.showOnAnimalPage,
|
||||
parentId
|
||||
},
|
||||
});
|
||||
|
||||
@ -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 })) }
|
||||
|
||||
Reference in New Issue
Block a user