The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Sync and ban-check Tolt partners whose import fails after enrollment
Rafi875c70f48c7f
diff --git a/apps/web/lib/tolt/import-partners.ts b/apps/web/lib/tolt/import-partners.tsindex 1c790abad8..1aca448670 100644--- a/apps/web/lib/tolt/import-partners.ts+++ b/apps/web/lib/tolt/import-partners.ts@@ -67,6 +67,10 @@ export async function importPartners(payload: ToltImportPayload) {}if (activeAffiliates.length > 0) {+ // Filled as soon as each enrollment is saved, so a partner whose later+ // step throws still reaches the search sync and the ban check.+ const enrolledPartnerIds: string[] = [];+const partnersPromise = await Promise.allSettled(activeAffiliates.map((affiliate) =>createPartner({@@ -81,6 +85,7 @@ export async function importPartners(payload: ToltImportPayload) {referralRewardId: defaultGroup.referralRewardId,discountId: defaultGroup.discountId,},+ enrolledPartnerIds,}),),);@@ -91,19 +96,19 @@ export async function importPartners(payload: ToltImportPayload) {).map((p) => p.value);- if (partners.length > 0) {- // Queue an index update because the imported partners were enrolled.- // Queued per page rather than per partner.- await queuePartnerSearchSync({- partnerIds: partners.map((p) => p.id),- programId,- });+ // Queue an index update because the imported partners were enrolled.+ // Queued per page rather than per partner.+ await queuePartnerSearchSync({+ partnerIds: enrolledPartnerIds,+ programId,+ });- await detectAndRecordNetworkLevelBans({- programId,- partnerIds: partners.map((p) => p.id),- });+ await detectAndRecordNetworkLevelBans({+ programId,+ partnerIds: enrolledPartnerIds,+ });+ if (partners.length > 0) {await toltImporter.addPartners({programId,partnerIds: partners.map((p) => p.id),@@ -141,6 +146,7 @@ async function createPartner({program,affiliate,defaultGroupAttributes,+ enrolledPartnerIds,}: {program: Program;affiliate: ToltAffiliate;@@ -153,6 +159,7 @@ async function createPartner({referralRewardId: string | null;discountId: string | null;};+ enrolledPartnerIds: string[];}) {const partner = await prisma.partner.upsert({where: {@@ -182,6 +189,8 @@ async function createPartner({},});+ enrolledPartnerIds.push(partner.id);+if (!preservedBan) {await approveLinkedApplication({applicationId: enrollment.applicationId,