From 77f0f378547932302d07dec6403819da31cc6cc8 Mon Sep 17 00:00:00 2001 From: Carlos Date: Tue, 19 Nov 2024 17:57:35 +0100 Subject: [PATCH] fix count for giveth stats recurring donations --- src/services/recurringDonationService.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/services/recurringDonationService.ts b/src/services/recurringDonationService.ts index f1b41ba45..3f800ed11 100644 --- a/src/services/recurringDonationService.ts +++ b/src/services/recurringDonationService.ts @@ -428,18 +428,19 @@ export const recurringDonationsCountPerDateRange = async ( ): Promise => { const query = RecurringDonation.createQueryBuilder('recurringDonation') .select('COALESCE(COUNT(recurringDonation.id), 0)', 'count') + .innerJoin('recurringDonation.donations', 'donations') .where('recurringDonation.status != :status', { status: RECURRING_DONATION_STATUS.FAILED, }); if (fromDate) { - query.andWhere('recurringDonation.createdAt >= :fromDate', { + query.andWhere('donations.createdAt >= :fromDate', { fromDate: new Date(fromDate), }); } if (toDate) { - query.andWhere('recurringDonation.createdAt <= :toDate', { + query.andWhere('donations.createdAt <= :toDate', { toDate: new Date(toDate), }); } @@ -477,18 +478,19 @@ export const recurringDonationsCountPerDateRangePerMonth = async ( const query = RecurringDonation.createQueryBuilder('recurringDonation') .select('COUNT(recurringDonation.id)', 'total') .addSelect("TO_CHAR(recurringDonation.createdAt, 'YYYY/MM')", 'date') + .innerJoin('recurringDonation.donations', 'donations') .where('recurringDonation.status != :status', { status: RECURRING_DONATION_STATUS.FAILED, }); if (fromDate) { - query.andWhere('recurringDonation.createdAt >= :fromDate', { + query.andWhere('donations.createdAt >= :fromDate', { fromDate: new Date(fromDate), }); } if (toDate) { - query.andWhere('recurringDonation.createdAt <= :toDate', { + query.andWhere('donations.createdAt <= :toDate', { toDate: new Date(toDate), }); } @@ -672,22 +674,23 @@ export const recurringDonationsCountPerToken = async (params: { }): Promise<{ token: string; total: number }[]> => { const { fromDate, toDate, networkId, onlyVerified } = params; const query = RecurringDonation.createQueryBuilder('recurringDonation') - .select('recurringDonation.currency', 'token') + .select('donations.currency', 'token') .addSelect('COALESCE(COUNT(recurringDonation.id), 0)', 'total') + .innerJoin('recurringDonation.donations', 'donations') .where('recurringDonation.status != :status', { status: RECURRING_DONATION_STATUS.FAILED, }) - .groupBy('recurringDonation.currency') + .groupBy('donations.currency') .having('COUNT(recurringDonation.id) > 0'); if (fromDate) { - query.andWhere('recurringDonation.createdAt >= :fromDate', { + query.andWhere('donations.createdAt >= :fromDate', { fromDate: new Date(fromDate), }); } if (toDate) { - query.andWhere('recurringDonation.createdAt <= :toDate', { + query.andWhere('donations.createdAt <= :toDate', { toDate: new Date(toDate), }); }