Update delete bookmark category route to check if category has 0 bookmarks

master
TZGyn 2 years ago
parent 6d3ce29e85
commit 186f8b8aff
Signed by: TZGyn
GPG Key ID: 122EAF77AE81FD4A

@ -51,6 +51,23 @@ export const DELETE = async (request: NextRequest) => {
const bookmarkId = body.bookmarkCategoryId const bookmarkId = body.bookmarkCategoryId
const selectedBookmarkCategory = await db.query.bookmarkCategory.findFirst({
where: (bookmarkCategory, { eq }) =>
eq(bookmarkCategory.id, bookmarkId),
with: {
bookmark: true,
},
})
if (!selectedBookmarkCategory)
return NextResponse.json({ message: 'Invalid Category' })
if (selectedBookmarkCategory.bookmark.length) {
return NextResponse.json({
message: 'Category Must Have No Bookmarks To Be Deleted',
})
}
await db await db
.delete(bookmarkCategory) .delete(bookmarkCategory)
.where( .where(

Loading…
Cancel
Save