From ce9d15465ff6e08832813c41b31c630a2efeb5be Mon Sep 17 00:00:00 2001 From: Leo Huang <77544794+leogjhuang@users.noreply.github.com> Date: Thu, 11 Apr 2024 00:04:01 -0400 Subject: [PATCH] Update permit holders report 2 (#358) * Update permit holders report 2 * Format postal code --- lib/reports/resolvers.ts | 39 ++++++++++++++++++++++++--------------- tools/admin/reports.ts | 16 +++++++++++++--- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/lib/reports/resolvers.ts b/lib/reports/resolvers.ts index 53d3dbc2..83a2e232 100644 --- a/lib/reports/resolvers.ts +++ b/lib/reports/resolvers.ts @@ -10,7 +10,12 @@ import { PaymentType, } from '@lib/graphql/types'; import { SortOrder } from '@tools/types'; -import { formatAddress, formatFullName, formatPhoneNumber } from '@lib/utils/format'; // Formatting utils +import { + formatFullName, + formatPhoneNumber, + formatPostalCode, + formatStreetAddress, +} from '@lib/utils/format'; // Formatting utils import { formatDateTimeYYYYMMDDHHMMSS, formatDateYYYYMMDD, @@ -107,8 +112,6 @@ export const generatePermitHoldersReport: Resolver< dateOfBirth, addressLine1, addressLine2, - city, - province, postalCode, guardian, permits, @@ -121,7 +124,8 @@ export const generatePermitHoldersReport: Resolver< applicantName: formatFullName(firstName, middleName, lastName), dateOfBirth: formatDateYYYYMMDD(dateOfBirth), age: moment().diff(dateOfBirth, 'years'), - homeAddress: formatAddress(addressLine1, addressLine2, city, postalCode, province), + address: formatStreetAddress(addressLine1, addressLine2), + postalCode: formatPostalCode(postalCode), phone: formatPhoneNumber(phone), rcdPermitId: `#${permits[0].rcdPermitId}`, permitType: permits[0].type, @@ -130,21 +134,26 @@ export const generatePermitHoldersReport: Resolver< guardianPOAName: guardian && formatFullName(guardian.firstName, guardian.middleName, guardian.lastName), guardianAddress: - guardian && - formatAddress( - guardian.addressLine1, - guardian.addressLine2, - guardian.city, - guardian.postalCode, - guardian.province - ), + guardian && formatStreetAddress(guardian.addressLine1, guardian.addressLine2), + guardianCity: guardian && guardian.city, + guardianPostalCode: + guardian && guardian.postalCode && formatPostalCode(guardian.postalCode), + guardianProvince: guardian && guardian.province, }; } ); - const csvHeaders = PERMIT_HOLDERS_COLUMNS.filter(({ value }) => columnsSet.has(value)).map( - ({ name, reportColumnId }) => ({ id: reportColumnId, title: name }) - ); + const filteredColumns = PERMIT_HOLDERS_COLUMNS.filter(({ value }) => columnsSet.has(value)); + const csvHeaders: Array<{ id: string; title: string }> = []; + for (const { name, reportColumnId } of filteredColumns) { + if (typeof reportColumnId === 'string') { + csvHeaders.push({ id: reportColumnId, title: name }); + } else { + for (const [columnLabel, columnId] of reportColumnId) { + csvHeaders.push({ id: columnId, title: columnLabel }); + } + } + } // Generate CSV string from csv object. const csvStringifier = createObjectCsvStringifier({ diff --git a/tools/admin/reports.ts b/tools/admin/reports.ts index 54253e45..f1e5b965 100644 --- a/tools/admin/reports.ts +++ b/tools/admin/reports.ts @@ -80,7 +80,7 @@ export const APPLICATIONS_COLUMNS: Array<{ export const PERMIT_HOLDERS_COLUMNS: Array<{ name: string; value: PermitHoldersReportColumn; - reportColumnId: string; + reportColumnId: string | Array<[string, string]>; }> = [ { name: 'User ID', @@ -105,7 +105,12 @@ export const PERMIT_HOLDERS_COLUMNS: Array<{ { name: 'Home Address', value: 'HOME_ADDRESS', - reportColumnId: 'homeAddress', + reportColumnId: [ + ['Address', 'address'], + ['City', 'city'], + ['Province', 'province'], + ['Postal Code', 'postalCode'], + ], }, { name: 'Email', @@ -130,7 +135,12 @@ export const PERMIT_HOLDERS_COLUMNS: Array<{ { name: 'Guardian/POA Address', value: 'GUARDIAN_POA_ADDRESS', - reportColumnId: 'guardianAddress', + reportColumnId: [ + ['Guardian/POA Address', 'guardianAddress'], + ['Guardian/POA City', 'guardianCity'], + ['Guardian/POA Province', 'guardianProvince'], + ['Guardian/POA Postal Code', 'guardianPostalCode'], + ], }, { name: 'Recent APP Number',