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.

fix import commissions

Steven Teyfaf438462a9c
diff --git a/apps/web/lib/firstpromoter/import-commissions.ts b/apps/web/lib/firstpromoter/import-commissions.ts
index baeb9c5c1c..96282b4b33 100644
--- a/apps/web/lib/firstpromoter/import-commissions.ts
+++ b/apps/web/lib/firstpromoter/import-commissions.ts
@@ -57,14 +57,29 @@ export async function importCommissions(payload: FirstPromoterImportPayload) {
break;
}
+ const commissionCustomers = commissions
+ .map(({ referral }) => referral)
+ .filter((c): c is NonNullable<typeof c> => c !== null && c !== undefined);
+
const customersData = await prisma.customer.findMany({
where: {
projectId: program.workspaceId,
- email: {
- in: commissions
- .map(({ referral }) => referral?.email)
- .filter((email): email is string => email !== null),
- },
+ OR: [
+ {
+ email: {
+ in: commissionCustomers.map(
+ ({ email }) => email.replace(" (moved)", ""), // remove the (moved) suffix
+ ),
+ },
+ },
+ {
+ externalId: {
+ in: commissionCustomers
+ .map(({ uid }) => uid)
+ .filter((c): c is NonNullable<typeof c> => c !== null),
+ },
+ },
+ ],
},
include: {
link: true,
diff --git a/apps/web/lib/firstpromoter/schemas.ts b/apps/web/lib/firstpromoter/schemas.ts
index 8dd6172723..9302620a15 100644
--- a/apps/web/lib/firstpromoter/schemas.ts
+++ b/apps/web/lib/firstpromoter/schemas.ts
@@ -141,5 +141,5 @@ export const firstPromoterCommissionSchema = z.object({
email: true,
uid: true,
})
- .nullable(),
+ .nullish(),
});