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.

Update mock-payout-completion.ts

Steven Tey4508fa552b67
diff --git a/apps/web/lib/sandbox/mock-payout-completion.ts b/apps/web/lib/sandbox/mock-payout-completion.ts
index de82f3312f..1ae4e3b9e4 100644
--- a/apps/web/lib/sandbox/mock-payout-completion.ts
+++ b/apps/web/lib/sandbox/mock-payout-completion.ts
@@ -1,7 +1,7 @@
import { prisma } from "@/lib/prisma";
import { sendBatchEmail } from "@dub/email";
import PartnerPayoutProcessed from "@dub/email/templates/partner-payout-processed";
-import { currencyFormatter } from "@dub/utils";
+import { chunk, currencyFormatter, log } from "@dub/utils";
import {
CommissionStatus,
Invoice,
@@ -74,17 +74,6 @@ export async function mockPayoutCompletion({
});
await prisma.$transaction([
- prisma.commission.updateMany({
- where: {
- payoutId: {
- in: payoutIds,
- },
- },
- data: {
- status: CommissionStatus.paid,
- },
- }),
-
prisma.payout.updateMany({
where: {
id: {
@@ -108,6 +97,37 @@ export async function mockPayoutCompletion({
}),
]);
+ const commissionIds = commissions.map((c) => c.id);
+
+ let totalUpdatedCommissions = 0;
+ for (const commissionIdsBatch of chunk(commissionIds, 250)) {
+ try {
+ const { count } = await prisma.commission.updateMany({
+ where: {
+ id: {
+ in: commissionIdsBatch,
+ },
+ },
+ data: {
+ status: CommissionStatus.paid,
+ },
+ });
+
+ totalUpdatedCommissions += count;
+ console.log(
+ `Marked ${totalUpdatedCommissions}/${commissionIds.length} commissions as paid`,
+ );
+ } catch (error) {
+ await log({
+ message: `[mockPayoutCompletion] Failed to mark commissions as paid for payouts ${payoutIds.join(
+ ", ",
+ )}: ${error.message}`,
+ type: "errors",
+ mention: true,
+ });
+ }
+ }
+
// Group partner -> payouts so we send only one email per partner when there are multiple payouts
const partnerPayouts = payouts.reduce(
(acc, payout) => {