Skip to content

Commit

Permalink
Update permit holders report 2 (#358)
Browse files Browse the repository at this point in the history
* Update permit holders report 2

* Format postal code
  • Loading branch information
leogjhuang authored Apr 11, 2024
1 parent b30e5a2 commit ce9d154
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 18 deletions.
39 changes: 24 additions & 15 deletions lib/reports/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -107,8 +112,6 @@ export const generatePermitHoldersReport: Resolver<
dateOfBirth,
addressLine1,
addressLine2,
city,
province,
postalCode,
guardian,
permits,
Expand All @@ -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,
Expand All @@ -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({
Expand Down
16 changes: 13 additions & 3 deletions tools/admin/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit ce9d154

Please sign in to comment.