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
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m20s
This commit is contained in:
@@ -70,7 +70,7 @@ export async function POST(req: NextRequest, { params }: { params: { slug: strin
|
||||
// Deduct from investor (returns updated user with new balance)
|
||||
prisma.user.update({ where: { id: session.user.id }, data: { balance: round2(investor.balance - amount) } }),
|
||||
// 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
|
||||
prisma.fundInvestment.upsert({
|
||||
where: { fundId_userId: { fundId: fund.id, userId: session.user.id } },
|
||||
|
||||
@@ -66,7 +66,7 @@ export async function POST(req: NextRequest, { params }: { params: { slug: strin
|
||||
// Return cash to investor
|
||||
prisma.user.update({ where: { id: session.user.id }, data: { balance: round2(investor.balance + payout) } }),
|
||||
// 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
|
||||
...(remainingShares > 0
|
||||
? [prisma.fundInvestment.update({
|
||||
|
||||
Reference in New Issue
Block a user