remove tag functionality
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { prisma } from "@/lib/api/db";
|
||||
|
||||
export default async function deleteTagById(userId: number, tagId: number) {
|
||||
if (!tagId)
|
||||
return { response: "Please choose a valid name for the tag.", status: 401 };
|
||||
|
||||
const targetTag = await prisma.tag.findUnique({
|
||||
where: {
|
||||
id: tagId,
|
||||
},
|
||||
});
|
||||
|
||||
if (targetTag?.ownerId !== userId)
|
||||
return {
|
||||
response: "Permission denied.",
|
||||
status: 401,
|
||||
};
|
||||
|
||||
const updatedTag = await prisma.tag.delete({
|
||||
where: {
|
||||
id: tagId,
|
||||
},
|
||||
});
|
||||
|
||||
return { response: updatedTag, status: 200 };
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { prisma } from "@/lib/api/db";
|
||||
import { Tag } from "@prisma/client";
|
||||
|
||||
export default async function updateTag(
|
||||
export default async function updeteTagById(
|
||||
userId: number,
|
||||
tagId: number,
|
||||
data: Tag
|
||||
|
||||
Reference in New Issue
Block a user