From 6dc5c77238427ff2ea2257ed3a6aa9fedccc9931 Mon Sep 17 00:00:00 2001 From: CarlosQ96 <92376054+CarlosQ96@users.noreply.github.com> Date: Tue, 12 Nov 2024 22:57:57 +0100 Subject: [PATCH] fix date filters for recurringdonation stats (#1872) --- src/repositories/recurringDonationRepository.ts | 3 ++- src/services/recurringDonationService.ts | 14 +++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/repositories/recurringDonationRepository.ts b/src/repositories/recurringDonationRepository.ts index 7dec0dea1..d7b05cb99 100644 --- a/src/repositories/recurringDonationRepository.ts +++ b/src/repositories/recurringDonationRepository.ts @@ -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], diff --git a/src/services/recurringDonationService.ts b/src/services/recurringDonationService.ts index 647b187cd..5241fd2c9 100644 --- a/src/services/recurringDonationService.ts +++ b/src/services/recurringDonationService.ts @@ -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), }); } @@ -572,16 +572,16 @@ export const recurringDonationsStreamedCUsdTotalPerMonth = async ( ): Promise => { 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), }); } @@ -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), }); }