From c43ad29efd68e61689332a79d5901df27786648d Mon Sep 17 00:00:00 2001 From: Chinemerem Date: Sat, 16 Nov 2024 22:55:40 -0500 Subject: [PATCH] Add phone number and addresses to request report (#383) --- lib/graphql/types.ts | 2 ++ lib/reports/resolvers.ts | 27 ++++++++++++++++++++++++--- lib/reports/schema.ts | 2 ++ tools/admin/reports.ts | 35 +++++++++++++++++++++++++---------- 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/lib/graphql/types.ts b/lib/graphql/types.ts index dc050b9b..01950c8f 100644 --- a/lib/graphql/types.ts +++ b/lib/graphql/types.ts @@ -178,6 +178,8 @@ export type ApplicationsReportColumn = | 'APPLICANT_NAME' | 'APPLICANT_DATE_OF_BIRTH' | 'APP_NUMBER' + | 'PHONE_NUMBER' + | 'HOME_ADDRESS' | 'APPLICATION_DATE' | 'PAYMENT_METHOD' | 'FEE_AMOUNT' diff --git a/lib/reports/resolvers.ts b/lib/reports/resolvers.ts index 939c5eb4..87969820 100644 --- a/lib/reports/resolvers.ts +++ b/lib/reports/resolvers.ts @@ -223,6 +223,12 @@ export const generateApplicationsReport: Resolver< firstName: true, middleName: true, lastName: true, + addressLine1: true, + addressLine2: true, + city: true, + province: true, + postalCode: true, + phone: true, type: true, createdAt: true, paymentMethod: true, @@ -262,6 +268,10 @@ export const generateApplicationsReport: Resolver< firstName, middleName, lastName, + phone, + addressLine1, + addressLine2, + postalCode, type, createdAt, processingFee, @@ -292,6 +302,9 @@ export const generateApplicationsReport: Resolver< id: applicant?.id, applicantName: formatFullName(firstName, middleName, lastName), dateOfBirth: dateOfBirth && formatDateYYYYMMDD(dateOfBirth), + address: formatStreetAddress(addressLine1, addressLine2), + postalCode: formatPostalCode(postalCode), + phone: formatPhoneNumber(phone), rcdPermitId: permit?.rcdPermitId ? `#${permit.rcdPermitId}` : null, applicationDate: createdAt ? formatDateYYYYMMDDLocal(createdAt, true) : null, processingFee: `$${processingFee}`, @@ -314,9 +327,17 @@ export const generateApplicationsReport: Resolver< } ); - const csvHeaders = APPLICATIONS_COLUMNS.filter(({ value }) => columnsSet.has(value)).map( - ({ name, reportColumnId }) => ({ id: reportColumnId, title: name }) - ); + const filteredColumns = APPLICATIONS_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/lib/reports/schema.ts b/lib/reports/schema.ts index 62ea95f4..c0485c19 100644 --- a/lib/reports/schema.ts +++ b/lib/reports/schema.ts @@ -25,6 +25,8 @@ export default gql` APPLICANT_NAME APPLICANT_DATE_OF_BIRTH APP_NUMBER + PHONE_NUMBER + HOME_ADDRESS APPLICATION_DATE PAYMENT_METHOD FEE_AMOUNT diff --git a/tools/admin/reports.ts b/tools/admin/reports.ts index c019d3e5..ce75b470 100644 --- a/tools/admin/reports.ts +++ b/tools/admin/reports.ts @@ -12,7 +12,7 @@ export enum GenerateReportStep { export const APPLICATIONS_COLUMNS: Array<{ name: string; value: ApplicationsReportColumn; - reportColumnId: string; + reportColumnId: string | Array<[string, string]>; }> = [ { name: 'User ID', @@ -35,9 +35,24 @@ export const APPLICATIONS_COLUMNS: Array<{ reportColumnId: 'rcdPermitId', }, { - name: 'Application Date', - value: 'APPLICATION_DATE', - reportColumnId: 'applicationDate', + name: 'Phone Number', + value: 'PHONE_NUMBER', + reportColumnId: 'phone', + }, + { + name: 'Home Address', + value: 'HOME_ADDRESS', + reportColumnId: [ + ['Address', 'address'], + ['City', 'city'], + ['Province', 'province'], + ['Postal Code', 'postalCode'], + ], + }, + { + name: 'Donation Amount', + value: 'DONATION_AMOUNT', + reportColumnId: 'donationAmount', }, { name: 'Payment Method', @@ -50,9 +65,9 @@ export const APPLICATIONS_COLUMNS: Array<{ reportColumnId: 'processingFee', }, { - name: 'Donation Amount', - value: 'DONATION_AMOUNT', - reportColumnId: 'donationAmount', + name: 'Second Donation Amount', + value: 'SECOND_DONATION_AMOUNT', + reportColumnId: 'secondDonationAmount', }, { name: 'Second Payment Method', @@ -65,9 +80,9 @@ export const APPLICATIONS_COLUMNS: Array<{ reportColumnId: 'secondProcessingFee', }, { - name: 'Second Donation Amount', - value: 'SECOND_DONATION_AMOUNT', - reportColumnId: 'secondDonationAmount', + name: 'Application Date', + value: 'APPLICATION_DATE', + reportColumnId: 'applicationDate', }, { name: 'Total Amount',