Skip to content

Commit

Permalink
sync all donations totals (#1594)
Browse files Browse the repository at this point in the history
* sync all donations totals

* add update qfroundmatching
  • Loading branch information
CarlosQ96 authored May 29, 2024
1 parent 497298b commit 8348342
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
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

0 comments on commit 8348342

Please sign in to comment.