The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Move all non-duplicate source fraud events to the merge target
Rafi0e2a45b633d9
diff --git a/apps/web/app/(ee)/api/workflows/merge-partner-accounts/route.ts b/apps/web/app/(ee)/api/workflows/merge-partner-accounts/route.tsindex d5e8660b03..db341dd170 100644--- a/apps/web/app/(ee)/api/workflows/merge-partner-accounts/route.ts+++ b/apps/web/app/(ee)/api/workflows/merge-partner-accounts/route.ts@@ -956,56 +956,35 @@ async function moveSourceFraudGroups({targetPartnerId: string;programId?: string;}) {- const sourceFraudGroups = await tx.fraudEventGroup.findMany({+ await tx.fraudEventGroup.updateMany({where: {partnerId: sourcePartnerId,status: FraudEventStatus.pending,...(programId && { programId }),},- select: {- id: true,- type: true,+ data: {+ partnerId: targetPartnerId,},});- if (sourceFraudGroups.length === 0) {- return;- }-- await tx.fraudEventGroup.updateMany({+ // Match events by partner, not by the groups moved above. A transfer moves+ // the enrollment's groups to the target but leaves their events on the+ // source. A duplicate-account event's partnerId names the duplicate, so+ // keep those. cleanupFraudEvents deletes them.+ await tx.fraudEvent.updateMany({where: {- id: {- in: pluck(sourceFraudGroups, "id"),+ partnerId: sourcePartnerId,+ ...(programId && { programId }),+ fraudEventGroup: {+ type: {+ not: FraudRuleType.partnerDuplicateAccount,+ },},- status: FraudEventStatus.pending,},data: {partnerId: targetPartnerId,},});-- // A duplicate-account event's partnerId names the duplicate, so keep the- // source ones. cleanupFraudEvents deletes them.- const otherGroupIds = pluck(- sourceFraudGroups.filter(- (group) => group.type !== FraudRuleType.partnerDuplicateAccount,- ),- "id",- );-- if (otherGroupIds.length > 0) {- await tx.fraudEvent.updateMany({- where: {- fraudEventGroupId: {- in: otherGroupIds,- },- partnerId: sourcePartnerId,- },- data: {- partnerId: targetPartnerId,- },- });- }}async function cleanupFraudEvents({