From d779355c4c79b38eb52f9cabe7bd03408bf4eee0 Mon Sep 17 00:00:00 2001 From: headlessdev Date: Mon, 14 Apr 2025 21:54:25 +0200 Subject: [PATCH] Prevent deletions of servers with associated applications --- app/api/servers/delete/route.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/api/servers/delete/route.ts b/app/api/servers/delete/route.ts index 82265da..ed7b852 100644 --- a/app/api/servers/delete/route.ts +++ b/app/api/servers/delete/route.ts @@ -9,6 +9,14 @@ export async function POST(request: NextRequest) { if (!id) { 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({ where: { id: id }