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 unban-partner.ts

Kiran K4cca5223f003
diff --git a/apps/web/lib/actions/partners/unban-partner.ts b/apps/web/lib/actions/partners/unban-partner.ts
index 4fbad7c984..163bffa503 100644
--- a/apps/web/lib/actions/partners/unban-partner.ts
+++ b/apps/web/lib/actions/partners/unban-partner.ts
@@ -2,6 +2,7 @@
import { trackActivityLog } from "@/lib/api/activity-log/track-activity-log";
import { trackCommissionStatusUpdate } from "@/lib/api/commissions/track-commission-update-activity-log";
+import { releaseHoldCommissions } from "@/lib/api/fraud/release-hold-commissions";
import { getGroupOrThrow } from "@/lib/api/groups/get-group-or-throw";
import { linkCache } from "@/lib/api/links/cache";
import { includeProgramEnrollment } from "@/lib/api/links/include-program-enrollment";
@@ -10,7 +11,7 @@ import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-progr
import { prisma } from "@/lib/prisma";
import { recordLink } from "@/lib/tinybird";
import { banPartnerSchema } from "@/lib/zod/schemas/partners";
-import { FraudRuleType } from "@prisma/client";
+import { FraudEventStatus, FraudRuleType } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
import { authActionClient } from "../safe-action";
import { throwIfNoPermission } from "../throw-if-no-permission";
@@ -168,6 +169,27 @@ export const unbanPartnerAction = authActionClient
}),
]);
+ // Find the cross-program ban groups (in other programs) whose only
+ // events originated from this program — deleting their events below will
+ // empty them out, so their held commissions must be released first.
+ const affectedFraudGroups = await prisma.fraudEventGroup.findMany({
+ where: {
+ partnerId,
+ type: FraudRuleType.partnerCrossProgramBan,
+ status: FraudEventStatus.pending,
+ fraudEvents: {
+ every: {
+ sourceProgramId: programId,
+ },
+ },
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ await releaseHoldCommissions(affectedFraudGroups.map((g) => g.id));
+
await prisma.$transaction([
// Since we're unbanning the partner, we need to
// clean up any pending cross-program ban alerts that originated from this program.