Skip to content

Commit

Permalink
sync all donations totals
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 committed May 29, 2024
1 parent 7554f78 commit 8950178
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 11 additions & 3 deletions src/services/donationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,17 @@ export const updateTotalDonationsOfProject = async (
`
UPDATE "project"
SET "totalDonations" = (
SELECT COALESCE(SUM(d."valueUsd"),0)
FROM "donation" as d
WHERE d."projectId" = $1 AND d."status" = 'verified'
(
SELECT COALESCE(SUM(d."valueUsd"),0)
FROM "donation" as d
WHERE d."projectId" = $1 AND d."status" = 'verified'
) + (
COALESCE((
SELECT SUM(q."matchingFundPriceUsd")
FROM "qfRoundHistory" as q
WHERE q."projectId" = $1
), 0)
)
)
WHERE "id" = $1
`,
Expand Down
8 changes: 1 addition & 7 deletions src/services/projectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
sumDonationValueUsdForQfRound,
} from '../repositories/donationRepository';
import { findProjectById } from '../repositories/projectRepository';
import { getQfRoundHistoryMatchingValueUsd } from '../repositories/qfRoundHistoryRepository';

export const getAppropriateSlug = async (
slugBase: string,
Expand Down Expand Up @@ -54,12 +53,7 @@ export const updateProjectStatistics = async (projectId: number) => {
project.countUniqueDonorsForActiveQfRound = 0;
}

const projectQfRoundHistoryMatching = await getQfRoundHistoryMatchingValueUsd(
project.id,
);

project.sumDonationValueUsd =
(await sumDonationValueUsd(project.id)) + projectQfRoundHistoryMatching;
project.sumDonationValueUsd = await sumDonationValueUsd(project.id);
project.countUniqueDonors = await countUniqueDonors(project.id);
await project.save();
};
Expand Down

0 comments on commit 8950178

Please sign in to comment.