Skip to content

Commit

Permalink
Use short dates in hosted collectives export (#579)
Browse files Browse the repository at this point in the history
* refact: use short dates in hosted collectives export

* refact: export emails in contact notation
  • Loading branch information
kewitz authored Oct 16, 2024
1 parent 8a1cda2 commit 2943bd3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/server/controllers/hosted-collectives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import gqlV2 from 'graphql-tag';
import { compact, get, pick, toNumber, trim } from 'lodash';
import moment from 'moment';

import { amountAsString } from '../lib/formatting';
import { amountAsString, formatContact, shortDate } from '../lib/formatting';
import { graphqlRequest } from '../lib/graphql';
import { applyMapping, parseToBooleanDefaultFalse, parseToBooleanDefaultTrue, splitEnums } from '../lib/utils';
import { logger } from '../logger';
Expand Down Expand Up @@ -170,18 +170,18 @@ const csvMapping = {
description: 'description',
website: 'website',
currency: 'currency',
approvedAt: 'approvedAt',
approvedAt: (account) => shortDate(account.approvedAt),
hostFeePercent: 'hostFeePercent',
balance: (account) => amountAsString(account.stats.balance),
adminEmails: (account) => compact(account.admins?.nodes.map((member) => member.account?.email)).join(','),
adminEmails: (account) => compact(account.admins?.nodes.map((member) => formatContact(member.account))).join(', '),
adminCount: (account) => account.admins?.totalCount,
firstContributionDate: (account) => account.firstContributionReceived?.nodes[0]?.createdAt,
lastContributionDate: (account) => account.lastContributionReceived?.nodes[0]?.createdAt,
firstContributionDate: (account) => shortDate(account.firstContributionReceived?.nodes[0]?.createdAt),
lastContributionDate: (account) => shortDate(account.lastContributionReceived?.nodes[0]?.createdAt),
totalAmountOfContributions: (account) =>
account.stats.totalAmountReceived && amountAsString(account.stats.totalAmountReceived),
totalNumberOfContributions: (account) => account.numberOfContributions?.totalCount,
firstExpenseDate: (account) => account.firstExpenseReceived?.nodes[0]?.createdAt,
lastExpenseDate: (account) => account.lastExpenseReceived?.nodes[0]?.createdAt,
firstExpenseDate: (account) => shortDate(account.firstExpenseReceived?.nodes[0]?.createdAt),
lastExpenseDate: (account) => shortDate(account.lastExpenseReceived?.nodes[0]?.createdAt),
numberOfExpenses: (account) => account.numberOfExpenses?.totalCount,
};

Expand Down
7 changes: 7 additions & 0 deletions src/server/lib/formatting.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import moment from 'moment';

export const amountAsString = (amount: { currency: string; value: number }) => {
const amountAsString = new Intl.NumberFormat('en-US', { style: 'currency', currency: amount.currency }).format(
amount.value,
Expand All @@ -17,3 +19,8 @@ export const accountNameAndLegalName = (account: { name?: string; legalName?: st
return legalName || name;
}
};

export const shortDate = (date: string) => moment.utc(date).format('YYYY-MM-DD');

export const formatContact = (contact: { name?: string; email: string }) =>
`${contact.name ? `${contact.name} ` : ''}<${contact.email}>`;

0 comments on commit 2943bd3

Please sign in to comment.