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 }