From f2cd51a43b42703baa88ae8135ea831f83eaa4e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Hodierne?= Date: Thu, 2 May 2024 11:19:49 +0200 Subject: [PATCH] follow up on account contributors CSV (#561) --- .../controllers/account-contributors.js | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/server/controllers/account-contributors.js b/src/server/controllers/account-contributors.js index 3163668d..bbdb4e7a 100644 --- a/src/server/controllers/account-contributors.js +++ b/src/server/controllers/account-contributors.js @@ -36,6 +36,7 @@ const contributorsQuery = gqlV2/* GraphQL */ ` ) { totalCount nodes { + status frequency amount { value @@ -48,13 +49,14 @@ const contributorsQuery = gqlV2/* GraphQL */ ` createdAt } } - pausedRecurringContributions: orders( + inactiveRecurringContributions: orders( oppositeAccount: { slug: $slug } - status: PAUSED + status: [PAUSED, CANCELLED] orderBy: { field: CREATED_AT, direction: DESC } ) { totalCount nodes { + status frequency amount { value @@ -98,27 +100,29 @@ const contributorsQuery = gqlV2/* GraphQL */ ` } `; -const activeRecurringContribution = (m) => - get(m, 'account.activeRecurringContributions.nodes[0]') || get(m, 'account.pausedRecurringContributions.nodes[0]'); +const recurringContribution = (m) => + get(m, 'account.activeRecurringContributions.nodes[0]') || get(m, 'account.inactiveRecurringContributions.nodes[0]'); const csvMapping = { contributorUrl: (m) => `${process.env.WEBSITE_URL}/${m.account.slug}`, contributorName: 'account.name', + contributorEmail: 'account.email', + contributorWebsite: 'account.website', contributorType: 'account.type', totalContributions: 'totalDonations.value', currency: 'totalDonations.currency', - 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) => + recurringContribution: (m) => (recurringContribution(m) ? 'yes' : 'no'), + recurringContributionStatus: (m) => get(recurringContribution(m), 'status'), + recurringContributionTier: (m) => get(recurringContribution(m), 'tier.name'), + recurringContributionAmount: (m) => get(recurringContribution(m), 'amount.value'), + recurringContributionCurrency: (m) => get(recurringContribution(m), 'amount.currency'), + recurringContributionFrequency: (m) => get(recurringContribution(m), 'frequency'), + contributorFirstContributionDate: (m) => m.account.firstContributions.nodes[0] && moment.utc(m.account.firstContributions.nodes[0].createdAt).format('YYYY-MM-DD'), - latestContributionDate: (m) => + contributorLatestContributionDate: (m) => m.account.latestContributions.nodes[0] && moment.utc(m.account.latestContributions.nodes[0].createdAt).format('YYYY-MM-DD'), - email: 'account.email', - website: 'account.website', }; const allFields = Object.keys(csvMapping); @@ -126,17 +130,19 @@ const allFields = Object.keys(csvMapping); const defaultFields = [ 'contributorUrl', 'contributorName', + 'contributorEmail', + 'contributorWebsite', 'contributorType', + 'contributorFirstContributionDate', + 'contributorLatestContributionDate', 'totalContributions', 'currency', - 'activeRecurringContribution', - 'activeRecurringContributionTier', - 'activeRecurringContributionAmount', - 'activeRecurringContributionFrequency', - 'firstContributionDate', - 'latestContributionDate', - 'email', - 'website', + 'recurringContribution', + 'recurringContributionTier', + 'recurringContributionStatus', + 'recurringContributionAmount', + 'recurringContributionCurrency', + 'recurringContributionFrequency', ]; const applyMapping = (mapping, row) => {