The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
If the sale has already been paid, we need to update the payout
Kiran K0d33666cf4c8
diff --git a/apps/web/app/api/partners/sales/route.ts b/apps/web/app/api/partners/sales/route.tsindex 696dd5f455..e4e41c5c00 100644--- a/apps/web/app/api/partners/sales/route.ts+++ b/apps/web/app/api/partners/sales/route.ts@@ -62,9 +62,13 @@ export const PATCH = withWorkspace(});}+ // Recalculate the earnings based on the new amountconst earnings = calculateSaleEarnings({reward,- sale,+ sale: {+ amount,+ quantity: sale.quantity,+ },});const updatedSale = await prisma.commission.update({@@ -77,6 +81,24 @@ export const PATCH = withWorkspace(},});+ // If the sale has already been paid, we need to update the payout+ if (sale.status === "processed" && sale.payoutId) {+ const earningsDifference = earnings - sale.earnings;++ await prisma.payout.update({+ where: {+ id: sale.payoutId,+ },+ data: {+ amount: {+ ...(earningsDifference < 0+ ? { decrement: Math.abs(earningsDifference) }+ : { increment: earningsDifference }),+ },+ },+ });+ }+return NextResponse.json(ProgramSaleSchema.parse(updatedSale));},{