Skip to content

Commit faf4384

Browse files
committed
fix import commissions
1 parent e590b5f commit faf4384

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

apps/web/lib/firstpromoter/import-commissions.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,29 @@ export async function importCommissions(payload: FirstPromoterImportPayload) {
5757
break;
5858
}
5959

60+
const commissionCustomers = commissions
61+
.map(({ referral }) => referral)
62+
.filter((c): c is NonNullable<typeof c> => c !== null && c !== undefined);
63+
6064
const customersData = await prisma.customer.findMany({
6165
where: {
6266
projectId: program.workspaceId,
63-
email: {
64-
in: commissions
65-
.map(({ referral }) => referral?.email)
66-
.filter((email): email is string => email !== null),
67-
},
67+
OR: [
68+
{
69+
email: {
70+
in: commissionCustomers.map(
71+
({ email }) => email.replace(" (moved)", ""), // remove the (moved) suffix
72+
),
73+
},
74+
},
75+
{
76+
externalId: {
77+
in: commissionCustomers
78+
.map(({ uid }) => uid)
79+
.filter((c): c is NonNullable<typeof c> => c !== null),
80+
},
81+
},
82+
],
6883
},
6984
include: {
7085
link: true,

apps/web/lib/firstpromoter/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,5 @@ export const firstPromoterCommissionSchema = z.object({
141141
email: true,
142142
uid: true,
143143
})
144-
.nullable(),
144+
.nullish(),
145145
});

0 commit comments

Comments
 (0)