File tree Expand file tree Collapse file tree 2 files changed +21
-6
lines changed
apps/web/lib/firstpromoter Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff line change @@ -141,5 +141,5 @@ export const firstPromoterCommissionSchema = z.object({
141141 email : true ,
142142 uid : true ,
143143 } )
144- . nullable ( ) ,
144+ . nullish ( ) ,
145145} ) ;
You can’t perform that action at this time.
0 commit comments