The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Improve commission update flow
Steven Tey23ec49e81b04
diff --git a/apps/web/app/(ee)/api/commissions/[commissionId]/route.ts b/apps/web/app/(ee)/api/commissions/[commissionId]/route.tsindex 2c4f01a178..a15fdf7565 100644--- a/apps/web/app/(ee)/api/commissions/[commissionId]/route.ts+++ b/apps/web/app/(ee)/api/commissions/[commissionId]/route.ts@@ -113,17 +113,20 @@ export const PATCH = withWorkspace(});}+ const isRefunded = finalAmount === 0 || finalEarnings === 0;+const updatedCommission = await prisma.commission.update({where: {id: commission.id,},data: {- amount: finalAmount,- earnings: finalEarnings,- status,- // need to update payoutId to null if the commission has no earnings- // or is being updated to refunded, duplicate, canceled, or fraudulent- ...(finalEarnings === 0 || status ? { payoutId: null } : {}),+ // if the sale/commission is fully refunded, we don't need to update the amount or earnings+ // we just update status to refunded and exclude it from the payout+ // same goes for updating status to refunded, duplicate, canceled, or fraudulent+ amount: isRefunded ? undefined : finalAmount,+ earnings: isRefunded ? undefined : finalEarnings,+ status: status ?? (isRefunded ? "refunded" : undefined),+ ...(status || isRefunded ? { payoutId: null } : {}),},include: {customer: true,