From 20f939799d3c32330f63cd79d4457dfd9468ec28 Mon Sep 17 00:00:00 2001 From: Mike Johnston Date: Wed, 18 Mar 2026 23:14:33 -0400 Subject: [PATCH] fix fund fk on deletes --- src/app/api/admin/funds/[fundId]/route.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 })