Skip to content

Commit

Permalink
Add phone number and addresses to request report (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinemeremChigbo authored Nov 17, 2024
1 parent 6f0e585 commit c43ad29
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
2 changes: 2 additions & 0 deletions lib/graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
27 changes: 24 additions & 3 deletions lib/reports/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -262,6 +268,10 @@ export const generateApplicationsReport: Resolver<
firstName,
middleName,
lastName,
phone,
addressLine1,
addressLine2,
postalCode,
type,
createdAt,
processingFee,
Expand Down Expand Up @@ -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}`,
Expand All @@ -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({
Expand Down
2 changes: 2 additions & 0 deletions lib/reports/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 25 additions & 10 deletions tools/admin/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit c43ad29

Please sign in to comment.