From c679f01c025f741bc4c2d0f10227fab73628d73f Mon Sep 17 00:00:00 2001 From: Leo Kewitz Date: Wed, 16 Oct 2024 13:17:52 +0200 Subject: [PATCH] refact: export emails in contact notation --- src/server/controllers/hosted-collectives.ts | 4 ++-- src/server/lib/formatting.ts | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/server/controllers/hosted-collectives.ts b/src/server/controllers/hosted-collectives.ts index f82e569a..b6d4625e 100644 --- a/src/server/controllers/hosted-collectives.ts +++ b/src/server/controllers/hosted-collectives.ts @@ -6,7 +6,7 @@ import gqlV2 from 'graphql-tag'; import { compact, get, pick, toNumber, trim } from 'lodash'; import moment from 'moment'; -import { amountAsString, shortDate } 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'; @@ -173,7 +173,7 @@ const csvMapping = { 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) => shortDate(account.firstContributionReceived?.nodes[0]?.createdAt), lastContributionDate: (account) => shortDate(account.lastContributionReceived?.nodes[0]?.createdAt), diff --git a/src/server/lib/formatting.ts b/src/server/lib/formatting.ts index 51c20164..c5c3774b 100644 --- a/src/server/lib/formatting.ts +++ b/src/server/lib/formatting.ts @@ -21,3 +21,6 @@ export const accountNameAndLegalName = (account: { name?: string; legalName?: st }; 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}>`;