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

Feature paused recurring contributions as active #558

Merged
merged 1 commit into from
Apr 16, 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
30 changes: 26 additions & 4 deletions src/server/controllers/account-contributors.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ const contributorsQuery = gqlV2/* GraphQL */ `
createdAt
}
}
pausedRecurringContributions: orders(
searchTerm: $slug
Copy link
Member

Choose a reason for hiding this comment

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

Here again, I think we should rather introduce an account parameter as searchTerm could return wrong values (eg. "opensource" could return an order with description "Contribution to Babel's OpenSource Fund").

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm looking at that.

status: PAUSED
orderBy: { field: CREATED_AT, direction: DESC }
) {
totalCount
nodes {
frequency
amount {
value
currency
}
tier {
slug
name
}
createdAt
}
}
latestContributions: transactions(
limit: 1
kind: CONTRIBUTION
Expand Down Expand Up @@ -79,16 +98,19 @@ const contributorsQuery = gqlV2/* GraphQL */ `
}
`;

const activeRecurringContribution = (m) =>
get(m, 'account.activeRecurringContributions.nodes[0]') || get(m, 'account.pausedRecurringContributions.nodes[0]');

const csvMapping = {
contributorUrl: (m) => `${process.env.WEBSITE_URL}/${m.account.slug}`,
contributorName: 'account.name',
contributorType: 'account.type',
totalContributions: 'totalDonations.value',
currency: 'totalDonations.currency',
activeRecurringContribution: (m) => (m.account.activeRecurringContributions.nodes.length ? 'yes' : 'no'),
activeRecurringContributionTier: (m) => get(m, 'account.activeRecurringContributions.nodes[0].tier.slug'), // Or name?
activeRecurringContributionAmount: (m) => get(m, 'account.activeRecurringContributions.nodes[0].amount.value'), // Currency?
activeRecurringContributionFrequency: (m) => get(m, 'account.activeRecurringContributions.nodes[0].frequency'),
activeRecurringContribution: (m) => (activeRecurringContribution(m) ? 'yes' : 'no'),
activeRecurringContributionTier: (m) => get(activeRecurringContribution(m), 'tier.slug'),
activeRecurringContributionAmount: (m) => get(activeRecurringContribution(m), 'amount.value'), // Currency?
activeRecurringContributionFrequency: (m) => get(activeRecurringContribution(m), 'frequency'),
firstContributionDate: (m) =>
m.account.firstContributions.nodes[0] &&
moment.utc(m.account.firstContributions.nodes[0].createdAt).format('YYYY-MM-DD'),
Expand Down