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.

Guard normalized email backfill and recompute on reattribution

Kiran Kedea8ddf5764
diff --git a/apps/web/lib/api/customers/backfill-customer-normalized-email.ts b/apps/web/lib/api/customers/backfill-customer-normalized-email.ts
index c1af40ab76..bca31b7724 100644
--- a/apps/web/lib/api/customers/backfill-customer-normalized-email.ts
+++ b/apps/web/lib/api/customers/backfill-customer-normalized-email.ts
@@ -81,6 +81,7 @@ export async function backfillCustomerNormalizedEmailBatch({
END
WHERE id IN (${Prisma.join(updates.map((u) => u.id))})
AND normalizedEmail IS NULL
+ AND email IS NOT NULL
`;
return {
diff --git a/apps/web/lib/api/customers/reattribute-customer.ts b/apps/web/lib/api/customers/reattribute-customer.ts
index 0a667d0036..74a91c3bd5 100644
--- a/apps/web/lib/api/customers/reattribute-customer.ts
+++ b/apps/web/lib/api/customers/reattribute-customer.ts
@@ -3,6 +3,7 @@ import { updateLinkStatsForImporter } from "@/lib/api/links/update-link-stats-fo
import { syncPartnerLinksStats } from "@/lib/api/partners/sync-partner-links-stats";
import { syncTotalCommissions } from "@/lib/api/partners/sync-total-commissions";
import { MUTABLE_PAYOUT_STATUSES } from "@/lib/constants/payouts";
+import { getNormalizedEmail } from "@/lib/email/normalize-email";
import { queuePartnerCommissionCreation } from "@/lib/partners/queue-partner-commission-creation";
import { prisma } from "@/lib/prisma";
import { getCustomerEventsTB } from "@/lib/tinybird/get-customer-events-tb";
@@ -163,7 +164,7 @@ export async function recreateCustomerForReattribution({
id: newCustomerId,
name: customer.name,
email: customer.email,
- normalizedEmail: customer.normalizedEmail,
+ normalizedEmail: getNormalizedEmail(customer.email),
avatar: customer.avatar,
externalId: customer.externalId,
stripeCustomerId: customer.stripeCustomerId,