fix: improve delete library response message and add media deletion step
This commit is contained in:
parent
6f938243ad
commit
6c58219ea0
|
|
@ -10,12 +10,17 @@ export async function DELETE(request: NextRequest, { params: paramsPromise }: {
|
|||
}
|
||||
|
||||
try {
|
||||
// First, delete all media associated with this library
|
||||
db.prepare('DELETE FROM media WHERE library_id = ?').run(id);
|
||||
|
||||
// Then delete the library itself
|
||||
const info = db.prepare('DELETE FROM libraries WHERE id = ?').run(id);
|
||||
if (info.changes === 0) {
|
||||
return NextResponse.json({ error: 'Library not found' }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json({ message: 'Library deleted' });
|
||||
return NextResponse.json({ message: 'Library deleted successfully' });
|
||||
} catch (error: any) {
|
||||
console.error('Error deleting library:', error);
|
||||
return NextResponse.json({ error: error.message }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue