@@ -43,6 +43,7 @@ import {
4343 GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE ,
4444} from '../constants/gitcoin' ;
4545import { UserRankMaterializedView } from '../entities/userRanksMaterialized' ;
46+ import { DONATION_STATUS } from '../entities/donation' ;
4647
4748@ObjectType ( )
4849class UserRelatedAddressResponse {
@@ -128,6 +129,15 @@ class PaginatedUsers {
128129 totalCount : number ;
129130}
130131
132+ @ObjectType ( )
133+ class UsersData {
134+ @Field ( _type => [ User ] , { nullable : true } )
135+ users : User [ ] ;
136+
137+ @Field ( _type => Number , { nullable : true } )
138+ totalCount : number ;
139+ }
140+
131141// eslint-disable-next-line unused-imports/no-unused-imports
132142@Resolver ( _of => User )
133143export class UserResolver {
@@ -619,4 +629,65 @@ export class UserResolver {
619629 await userFromDB . save ( ) ;
620630 return true ;
621631 }
632+
633+ @Query ( _returns => UsersData )
634+ async getUsersVerificationStatus (
635+ @Arg ( 'hasDonated' , ( ) => Boolean , { nullable : true } ) hasDonated ?: boolean ,
636+ @Arg ( 'privadoVerified' , ( ) => Boolean , { nullable : true } )
637+ privadoVerified ?: boolean ,
638+ @Arg ( 'humanVerified' , ( ) => Boolean , { nullable : true } )
639+ humanVerified ?: boolean ,
640+ ) {
641+ const query = User . createQueryBuilder ( 'user' ) . select ( [
642+ 'user.id' ,
643+ 'user.walletAddress' ,
644+ 'user.passportScore' ,
645+ 'user.passportStamps' ,
646+ 'user.privadoVerifiedRequestIds' ,
647+ 'user.skipVerification' ,
648+ ] ) ;
649+ if ( hasDonated ) {
650+ query . andWhere (
651+ `EXISTS (
652+ SELECT 1 FROM donation d
653+ WHERE d."userId" = user.id AND d.status = :status
654+ )` ,
655+ { status : DONATION_STATUS . VERIFIED } ,
656+ ) ;
657+ }
658+
659+ if ( privadoVerified === true ) {
660+ // Add the filter for users who are privado verified
661+ query . andWhere (
662+ ':privadoRequestId = ANY (user.privadoVerifiedRequestIds)' ,
663+ {
664+ privadoRequestId : PrivadoAdapter . privadoRequestId ,
665+ } ,
666+ ) ;
667+ }
668+
669+ if ( humanVerified === true ) {
670+ query
671+ . andWhere (
672+ new Brackets ( qb => {
673+ qb . where ( 'user.passportScore >= :passportScoreThreshold' , {
674+ passportScoreThreshold : GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE ,
675+ } ) . orWhere ( 'user.analysisScore >= :analysisScoreThreshold' , {
676+ analysisScoreThreshold : GITCOIN_PASSPORT_MIN_VALID_ANALYSIS_SCORE ,
677+ } ) ;
678+ } ) ,
679+ )
680+ . andWhere (
681+ 'NOT (:privadoRequestId = ANY (user.privadoVerifiedRequestIds))' ,
682+ { privadoRequestId : PrivadoAdapter . privadoRequestId } ,
683+ ) ; // Negate the condition for privadoVerified
684+ }
685+
686+ const [ users , totalCount ] = await query . getManyAndCount ( ) ;
687+
688+ return {
689+ users : users ,
690+ totalCount : totalCount ,
691+ } ;
692+ }
622693}
0 commit comments