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

Change recurringdonation status to exclude failed On STATS #1869

Merged
merged 1 commit into from
Nov 6, 2024
Merged
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
12 changes: 6 additions & 6 deletions src/services/recurringDonationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ export const recurringDonationsCountPerDateRange = async (
): Promise<number> => {
const query = RecurringDonation.createQueryBuilder('recurringDonation')
.select('COALESCE(COUNT(recurringDonation.id), 0)', 'count')
.where('recurringDonation.status = :status', {
status: RECURRING_DONATION_STATUS.ACTIVE,
.where('recurringDonation.status != :status', {
status: RECURRING_DONATION_STATUS.FAILED,
});

if (fromDate) {
Expand Down Expand Up @@ -477,8 +477,8 @@ export const recurringDonationsCountPerDateRangePerMonth = async (
const query = RecurringDonation.createQueryBuilder('recurringDonation')
.select('COUNT(recurringDonation.id)', 'total')
.addSelect("TO_CHAR(recurringDonation.createdAt, 'YYYY/MM')", 'date')
.where('recurringDonation.status = :status', {
status: RECURRING_DONATION_STATUS.ACTIVE,
.where('recurringDonation.status != :status', {
status: RECURRING_DONATION_STATUS.FAILED,
});

if (fromDate) {
Expand Down Expand Up @@ -672,8 +672,8 @@ export const recurringDonationsCountPerToken = async (params: {
const query = RecurringDonation.createQueryBuilder('recurringDonation')
.select('recurringDonation.currency', 'token')
.addSelect('COALESCE(COUNT(recurringDonation.id), 0)', 'total')
.where('recurringDonation.status = :status', {
status: RECURRING_DONATION_STATUS.ACTIVE,
.where('recurringDonation.status != :status', {
status: RECURRING_DONATION_STATUS.FAILED,
Comment on lines +675 to +676
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding status filter to USD total methods.

While the count methods now consistently exclude FAILED status, the related methods recurringDonationsStreamedCUsdTotal() and recurringDonationsStreamedCUsdTotalPerMonth() don't have this filter. Consider adding the same status filter to maintain consistency.

Example implementation:

  const query = RecurringDonation.createQueryBuilder(
    'recurringDonation',
  ).select('COALESCE(SUM(recurringDonation.totalUsdStreamed), 0)', 'total')
+ .where('recurringDonation.status != :status', {
+   status: RECURRING_DONATION_STATUS.FAILED,
+ });

Committable suggestion skipped: line range outside the PR's diff.

})
.groupBy('recurringDonation.currency')
.having('COUNT(recurringDonation.id) > 0');
Expand Down
Loading