Prevent deletions of servers with associated applications

This commit is contained in:
headlessdev 2025-04-14 21:54:25 +02:00
parent e844712c29
commit d779355c4c

View File

@ -10,6 +10,14 @@ export async function POST(request: NextRequest) {
return NextResponse.json({ error: "Missing ID" }, { status: 400 }); return NextResponse.json({ error: "Missing ID" }, { status: 400 });
} }
// Check if there are any applications associated with the server
const applications = await prisma.application.findMany({
where: { serverId: id }
});
if (applications.length > 0) {
return NextResponse.json({ error: "Cannot delete server with associated applications" }, { status: 400 });
}
await prisma.server.delete({ await prisma.server.delete({
where: { id: id } where: { id: id }
}); });