Skip to content

Commit

Permalink
fix date filters for recurringdonation stats (#1872)
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosQ96 authored Nov 12, 2024
1 parent be46140 commit 6dc5c77
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
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

0 comments on commit 6dc5c77

Please sign in to comment.