diff --git a/src/app/api/admin/funds/[fundId]/route.ts b/src/app/api/admin/funds/[fundId]/route.ts index c6e7aa1..a390e37 100644 --- a/src/app/api/admin/funds/[fundId]/route.ts +++ b/src/app/api/admin/funds/[fundId]/route.ts @@ -90,7 +90,9 @@ export async function DELETE( const fund = await prisma.hedgeFund.findUnique({ where: { id: params.fundId } }) if (!fund) return NextResponse.json({ error: 'Fund not found.' }, { status: 404 }) - // Delete shadow user cascades positions, trades, and the fund record + // Must delete fund first (it holds the FK to User), then delete the shadow user + // (which cascades positions and trades). + await prisma.hedgeFund.delete({ where: { id: fund.id } }) await prisma.user.delete({ where: { id: fund.userId } }) return NextResponse.json({ ok: true })