Skip to content

Commit

Permalink
refact: use short dates in hosted collectives export
Browse files Browse the repository at this point in the history
  • Loading branch information
kewitz committed Oct 16, 2024
1 parent 8a1cda2 commit 9aae826
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 6 additions & 6 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, 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(','),
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
4 changes: 4 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,5 @@ export const accountNameAndLegalName = (account: { name?: string; legalName?: st
return legalName || name;
}
};

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

0 comments on commit 9aae826

Please sign in to comment.