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

Fix date filters for recurringdonation stats #1872

Merged
merged 1 commit into from
Nov 12, 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
3 changes: 2 additions & 1 deletion src/repositories/recurringDonationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ export const updateRecurringDonationFromTheStreamDonations = async (
SELECT COALESCE(SUM(d."amount"), 0)
FROM donation as d
WHERE d."recurringDonationId" = $1
)
),
"updatedAt" = NOW()
WHERE "id" = $1
`,
[recurringDonationId],
Expand Down
14 changes: 7 additions & 7 deletions src/services/recurringDonationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,13 +529,13 @@ export const recurringDonationsStreamedCUsdTotal = async (
).select('COALESCE(SUM(recurringDonation.totalUsdStreamed), 0)', 'total');

if (fromDate) {
query.andWhere('recurringDonation.createdAt >= :fromDate', {
query.andWhere('recurringDonation.updatedAt >= :fromDate', {
fromDate: new Date(fromDate),
});
}

if (toDate) {
query.andWhere('recurringDonation.createdAt <= :toDate', {
query.andWhere('recurringDonation.updatedAt <= :toDate', {
toDate: new Date(toDate),
});
}
Expand Down Expand Up @@ -572,16 +572,16 @@ export const recurringDonationsStreamedCUsdTotalPerMonth = async (
): Promise<ResourcesTotalPerMonthAndYear[]> => {
const query = RecurringDonation.createQueryBuilder('recurringDonation')
.select('SUM(recurringDonation.totalUsdStreamed)', 'total')
.addSelect("TO_CHAR(recurringDonation.createdAt, 'YYYY/MM')", 'date');
.addSelect("TO_CHAR(recurringDonation.updatedAt, 'YYYY/MM')", 'date');

if (fromDate) {
query.andWhere('recurringDonation.createdAt >= :fromDate', {
query.andWhere('recurringDonation.updatedAt >= :fromDate', {
fromDate: new Date(fromDate),
});
}

if (toDate) {
query.andWhere('recurringDonation.createdAt <= :toDate', {
query.andWhere('recurringDonation.updatedAt <= :toDate', {
toDate: new Date(toDate),
});
}
Expand Down Expand Up @@ -627,13 +627,13 @@ export const recurringDonationsTotalPerToken = async (params: {
.having('SUM(recurringDonation.totalUsdStreamed) > 0');

if (fromDate) {
query.andWhere('recurringDonation.createdAt >= :fromDate', {
query.andWhere('recurringDonation.updatedAt >= :fromDate', {
fromDate: new Date(fromDate),
});
}

if (toDate) {
query.andWhere('recurringDonation.createdAt <= :toDate', {
query.andWhere('recurringDonation.updatedAt <= :toDate', {
toDate: new Date(toDate),
});
}
Expand Down
Loading