Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update permit holders report 2 #358

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading