Skip to content

Commit a6f7833

Browse files
Merge pull request #213 from GeneralMagicio/users-verification-status
added enpoint for users verification status
2 parents be48279 + bbd57d7 commit a6f7833

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

src/resolvers/userResolver.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
GITCOIN_PASSPORT_MIN_VALID_SCORER_SCORE,
4444
} from '../constants/gitcoin';
4545
import { UserRankMaterializedView } from '../entities/userRanksMaterialized';
46+
import { DONATION_STATUS } from '../entities/donation';
4647

4748
@ObjectType()
4849
class 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)
133143
export 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
}

test/graphqlQueries.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,3 +2314,26 @@ export const getTokenMarketCapChanges24hQuery = `
23142314
}
23152315
}
23162316
`;
2317+
2318+
export const getUsersVerificationStatus = `
2319+
query GetUsersVerificationStatus(
2320+
$hasDonated: Boolean
2321+
$privadoVerified: Boolean
2322+
$humanVerified: Boolean
2323+
) {
2324+
getUsersVerificationStatus(
2325+
hasDonated: $hasDonated
2326+
privadoVerified: $privadoVerified
2327+
humanVerified:$humanVerified
2328+
) {
2329+
users {
2330+
walletAddress
2331+
id
2332+
privadoVerified
2333+
hasEnoughGitcoinAnalysisScore
2334+
hasEnoughGitcoinPassportScore
2335+
skipVerification
2336+
}
2337+
totalCount
2338+
}
2339+
}`;

0 commit comments

Comments
 (0)