Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync all donations totals #1594

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/services/donationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@ 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'
)
)
WHERE "id" = $1
`,
Expand Down Expand Up @@ -367,6 +369,7 @@ export const syncDonationStatusWithBlockchainNetwork = async (params: {
});

// Update materialized view for project and qfRound data
await insertDonationsFromQfRoundHistory();
await refreshProjectEstimatedMatchingView();
await refreshProjectDonationSummaryView();

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
Loading