Skip to content

Commit

Permalink
Merge pull request #1758 from Giveth/master
Browse files Browse the repository at this point in the history
Master
  • Loading branch information
RamRamez authored Aug 9, 2024
2 parents e8b6365 + 88f562f commit 4d99fc4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "giveth-graphql-api",
"version": "1.24.3",
"version": "1.24.4",
"description": "Backend GraphQL server for Giveth originally forked from Topia",
"main": "./dist/index.js",
"dependencies": {
Expand Down Expand Up @@ -250,6 +250,5 @@
"ethers": "^5.5.4"
}
},
"author": "James Farrell",
"license": "ISC"
}
10 changes: 7 additions & 3 deletions src/repositories/qfRoundRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,11 @@ function getQfRoundTotalProjectsDonationsSumTestCases() {
});

it('should return 0 when no donations', async () => {
const { uniqueDonors, totalDonationUsd } = await getQfRoundStats(qfRound);
const { uniqueDonors, totalDonationUsd, donationsCount } =
await getQfRoundStats(qfRound);
expect(totalDonationUsd).to.equal(0);
expect(uniqueDonors).to.equal(0);
expect(donationsCount).to.equal(0);
});

it('should return correct value for single project', async () => {
Expand Down Expand Up @@ -266,9 +268,10 @@ function getQfRoundTotalProjectsDonationsSumTestCases() {
);
await refreshProjectEstimatedMatchingView();
const sum = await getQfRoundTotalSqrtRootSumSquared(qfRound.id);
const { uniqueDonors } = await getQfRoundStats(qfRound);
const { uniqueDonors, donationsCount } = await getQfRoundStats(qfRound);
expect(sum).to.equal(289);
expect(uniqueDonors).to.equal(3);
expect(donationsCount).to.equal(6);
});

it('should return correct value for multiple projects', async () => {
Expand Down Expand Up @@ -311,9 +314,10 @@ function getQfRoundTotalProjectsDonationsSumTestCases() {

await refreshProjectEstimatedMatchingView();
const sum = await getQfRoundTotalSqrtRootSumSquared(qfRound.id);
const { uniqueDonors } = await getQfRoundStats(qfRound);
const { uniqueDonors, donationsCount } = await getQfRoundStats(qfRound);
expect(sum).to.equal(289 * 5);
expect(uniqueDonors).to.equal(3);
expect(donationsCount).to.equal(12);
});
}

Expand Down
3 changes: 3 additions & 0 deletions src/repositories/qfRoundRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,13 @@ export const getQfRoundStats = async (
): Promise<{
uniqueDonors: number;
totalDonationUsd: number;
donationsCount: number;
}> => {
const { id: qfRoundId, beginDate, endDate } = qfRound;
const result = await Donation.createQueryBuilder('donation')
.select('COUNT(DISTINCT donation.fromWalletAddress)', 'uniqueDonors')
.addSelect('SUM(donation.valueUsd)', 'totalDonationUsd')
.addSelect('COALESCE(COUNT(donation.id), 0)', 'donationsCount')
.where('donation.qfRoundId = :qfRoundId', { qfRoundId })
.andWhere('donation.status = :status', { status: 'verified' })
.andWhere('donation.createdAt BETWEEN :beginDate AND :endDate', {
Expand All @@ -238,6 +240,7 @@ export const getQfRoundStats = async (
return {
uniqueDonors: parseInt(result.uniqueDonors) || 0,
totalDonationUsd: parseFloat(result.totalDonationUsd) || 0,
donationsCount: parseInt(result.donationsCount) || 0,
};
};

Expand Down
7 changes: 6 additions & 1 deletion src/resolvers/qfRoundResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export class QfRoundStatsResponse {
@Field()
uniqueDonors: number;

@Field()
donationsCount: number;

@Field()
allDonationsUsdValue: number;

Expand Down Expand Up @@ -203,9 +206,11 @@ export class QfRoundResolver {
if (!qfRound) {
return null;
}
const { uniqueDonors, totalDonationUsd } = await getQfRoundStats(qfRound);
const { uniqueDonors, totalDonationUsd, donationsCount } =
await getQfRoundStats(qfRound);
return {
uniqueDonors,
donationsCount,
allDonationsUsdValue: totalDonationUsd,
matchingPool: qfRound.allocatedFund,
qfRound,
Expand Down
1 change: 1 addition & 0 deletions test/graphqlQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,7 @@ export const qfRoundStatsQuery = `
slug: $slug
) {
uniqueDonors
donationsCount
allDonationsUsdValue
matchingPool
qfRound{
Expand Down

0 comments on commit 4d99fc4

Please sign in to comment.