Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

small updates to commission functions

Steven Tey6dc31e74e1d0
diff --git a/apps/web/lib/api/commissions/bulk-update-partner-commissions.ts b/apps/web/lib/api/commissions/bulk-update-partner-commissions.ts
index 5c6282e739..e855ac49c6 100644
--- a/apps/web/lib/api/commissions/bulk-update-partner-commissions.ts
+++ b/apps/web/lib/api/commissions/bulk-update-partner-commissions.ts
@@ -55,7 +55,7 @@ export async function bulkUpdatePartnerCommissions({
throw new DubApiError({
code: "not_found",
message:
- "One or more commissions were not found in this program or the IDs are invalid.",
+ "Cannot update commissions: One or more commissions were not found in this program or the IDs are invalid.",
});
}
@@ -120,10 +120,10 @@ export async function bulkUpdatePartnerCommissions({
},
});
- // Reconcile the payout amounts
- const payoutIds = commissions
- .filter((c) => c.payoutId)
- .map((c) => c.payoutId!);
+ // Reconcile the payout amounts (for unique payout IDs)
+ const payoutIds = Array.from(
+ new Set(commissions.filter((c) => c.payoutId).map((c) => c.payoutId!)),
+ );
await reconcilePayoutAmounts(payoutIds);
diff --git a/apps/web/lib/api/commissions/update-partner-commission.ts b/apps/web/lib/api/commissions/update-partner-commission.ts
index 64d412e36e..6217ba0662 100644
--- a/apps/web/lib/api/commissions/update-partner-commission.ts
+++ b/apps/web/lib/api/commissions/update-partner-commission.ts
@@ -204,6 +204,8 @@ export async function updatePartnerCommission({
amount: isRefunded ? undefined : finalSaleAmount,
earnings: isRefunded ? undefined : finalEarnings,
status: finalStatus,
+ // if finalStatus is defined, the commission needs to be removed from the payout
+ // because commission can only be updated to pending, canceled, refunded, duplicate, or fraudulent states
...(finalStatus ? { payoutId: null } : {}),
},
include: {