@@ -133,23 +133,29 @@ export class ReferralsService {
133133 const [ rows , total ] = await query . getManyAndCount ( ) ;
134134
135135 const signupCounts = rows . length
136- ? await this . dataSource . query < { referralEntityId : string ; signups : number } [ ] > (
137- `SELECT ua."referralEntityId", COUNT(DISTINCT ua."userId")::int AS signups
136+ ? await this . dataSource . query < { referralEntityId : string ; status : string ; count : number } [ ] > (
137+ `SELECT ua."referralEntityId", u."status", COUNT(DISTINCT ua."userId")::int AS count
138138 FROM "UserAttribution" ua
139139 JOIN "Users" u ON u."userId" = ua."userId"
140140 WHERE ua."referralEntityId" = ANY($1)
141- AND u."status" = 'active'
142- GROUP BY ua."referralEntityId"` ,
141+ AND u."status" IN ( 'active', 'inactive')
142+ GROUP BY ua."referralEntityId", u."status" ` ,
143143 [ rows . map ( ( r ) => r . id ) ] ,
144144 )
145145 : [ ] ;
146146
147- const signupMap = new Map ( signupCounts . map ( ( s ) => [ s . referralEntityId , s . signups ] ) ) ;
147+ const activeMap = new Map < string , number > ( ) ;
148+ const inactiveMap = new Map < string , number > ( ) ;
149+ for ( const row of signupCounts ) {
150+ if ( row . status === 'active' ) activeMap . set ( row . referralEntityId , row . count ) ;
151+ else if ( row . status === 'inactive' ) inactiveMap . set ( row . referralEntityId , row . count ) ;
152+ }
148153
149154 return {
150155 data : rows . map ( ( r ) => ( {
151156 ...this . normalizeReferral ( { ...r , referLink : buildReferLink ( r . slug ) } ) ,
152- signups : signupMap . get ( r . id ) ?? 0 ,
157+ signups : activeMap . get ( r . id ) ?? 0 ,
158+ inactive_signups : inactiveMap . get ( r . id ) ?? 0 ,
153159 } ) ) ,
154160 total,
155161 limit,
0 commit comments