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

Use short dates in hosted collectives export #579

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
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
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}>`;