fix: correct balance update logic for user and fund in investment and redemption processes
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m20s

This commit is contained in:
2026-03-21 01:33:04 -04:00
parent 74a204ea39
commit 9c3312ed75
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ export async function POST(req: NextRequest, { params }: { params: { slug: strin
// Deduct from investor (returns updated user with new balance) // Deduct from investor (returns updated user with new balance)
prisma.user.update({ where: { id: session.user.id }, data: { balance: round2(investor.balance - amount) } }), prisma.user.update({ where: { id: session.user.id }, data: { balance: round2(investor.balance - amount) } }),
// Add to fund's cash // Add to fund's cash
prisma.user.update({ where: { id: fund.userId }, data: { balance: { increment: amount } } }), prisma.user.update({ where: { id: fund.userId }, data: { balance: round2(fund.user.balance + amount) } }),
// Upsert FundInvestment record // Upsert FundInvestment record
prisma.fundInvestment.upsert({ prisma.fundInvestment.upsert({
where: { fundId_userId: { fundId: fund.id, userId: session.user.id } }, where: { fundId_userId: { fundId: fund.id, userId: session.user.id } },
+1 -1
View File
@@ -66,7 +66,7 @@ export async function POST(req: NextRequest, { params }: { params: { slug: strin
// Return cash to investor // Return cash to investor
prisma.user.update({ where: { id: session.user.id }, data: { balance: round2(investor.balance + payout) } }), prisma.user.update({ where: { id: session.user.id }, data: { balance: round2(investor.balance + payout) } }),
// Deduct from fund's cash // Deduct from fund's cash
prisma.user.update({ where: { id: fund.userId }, data: { balance: { decrement: payout } } }), prisma.user.update({ where: { id: fund.userId }, data: { balance: round2(fund.user.balance - payout) } }),
// Update or delete FundInvestment // Update or delete FundInvestment
...(remainingShares > 0 ...(remainingShares > 0
? [prisma.fundInvestment.update({ ? [prisma.fundInvestment.update({