2025-04-12 12:33:37 +02:00
|
|
|
import { NextResponse, NextRequest } from "next/server";
|
2025-04-13 21:10:17 +02:00
|
|
|
import { prisma } from "@/lib/prisma";
|
2025-04-12 12:33:37 +02:00
|
|
|
|
|
|
|
|
export async function POST(request: NextRequest) {
|
|
|
|
|
try {
|
|
|
|
|
const body = await request.json();
|
|
|
|
|
const id = Number(body.id);
|
|
|
|
|
|
|
|
|
|
if (!id) {
|
|
|
|
|
return NextResponse.json({ error: "Missing ID" }, { status: 400 });
|
|
|
|
|
}
|
2025-04-14 21:54:25 +02:00
|
|
|
|
|
|
|
|
// 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 });
|
|
|
|
|
}
|
2025-04-12 12:33:37 +02:00
|
|
|
|
|
|
|
|
await prisma.server.delete({
|
|
|
|
|
where: { id: id }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return NextResponse.json({ success: true });
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
return NextResponse.json({ error: error.message }, { status: 500 });
|
|
|
|
|
}
|
|
|
|
|
}
|