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 FirstPromoter partners whose import fails after enrollment
Rafi2d2273a0154b
diff --git a/apps/web/lib/firstpromoter/import-partners.ts b/apps/web/lib/firstpromoter/import-partners.tsindex 8634bf83db..1af4f55e03 100644--- a/apps/web/lib/firstpromoter/import-partners.ts+++ b/apps/web/lib/firstpromoter/import-partners.ts@@ -66,6 +66,10 @@ export async function importPartners(payload: FirstPromoterImportPayload) {);if (affiliates.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 enrolled: { id: string; partnerId: string }[] = [];+const results = await Promise.allSettled(affiliates.map((affiliate) => {const promoterCampaigns = affiliate.promoter_campaigns;@@ -80,6 +84,7 @@ export async function importPartners(payload: FirstPromoterImportPayload) {affiliate,group,userId,+ enrolled,});}),);@@ -94,19 +99,15 @@ export async function importPartners(payload: FirstPromoterImportPayload) {}});- const programEnrollments = results.flatMap((result) =>- result.status === "fulfilled" && result.value ? [result.value] : [],- );-// Queue an index update because the imported partners were enrolled.// Queued per page rather than per partner.await queuePartnerSearchSync({- enrollmentIds: programEnrollments.map(({ id }) => id),+ enrollmentIds: enrolled.map(({ id }) => id),});await detectAndRecordNetworkLevelBans({programId: program.id,- partnerIds: programEnrollments.map(({ partnerId }) => partnerId),+ partnerIds: enrolled.map(({ partnerId }) => partnerId),});}@@ -127,11 +128,13 @@ async function createPartnerAndLinks({affiliate,group,userId,+ enrolled,}: {program: Program;affiliate: FirstPromoterPartner;group: PartnerGroup & { partnerGroupDefaultLinks: PartnerGroupDefaultLink[] };userId: string;+ enrolled: { id: string; partnerId: string }[];}) {const partner = await prisma.partner.upsert({where: {@@ -211,6 +214,11 @@ async function createPartnerAndLinks({},});+ enrolled.push({+ id: programEnrollment.id,+ partnerId: programEnrollment.partnerId,+ });+if (!preservedBan) {await approveLinkedApplication({applicationId: programEnrollment.applicationId,@@ -251,8 +259,6 @@ async function createPartnerAndLinks({links,});} catch (error) {- // The enrollment is already committed, so it must still reach the- // page-level search sync even when link creation fails.console.error(`Failed to create links for imported affiliate ${affiliate.id}`,error,