From b94f013995cc2c65a16df1c6339fd74fcf48f576 Mon Sep 17 00:00:00 2001 From: Leo Huang <77544794+leogjhuang@users.noreply.github.com> Date: Sun, 25 Feb 2024 18:12:49 -0500 Subject: [PATCH] [Release] Version 0.3.1 (#354) * Fix second payment method reports (#352) * [Feature] Update permit holders report (#353) * Combine address lines 1 and 2 into one line * Add applicant age to permit holders report * Add recent app expiry date to permit holders report --- lib/graphql/types.ts | 5 ++++ lib/reports/resolvers.ts | 52 +++++++++++++++++++++------------------- lib/reports/schema.ts | 5 ++++ lib/utils/format.ts | 12 +++++----- tools/admin/reports.ts | 43 +++++++++++++++++++++------------ 5 files changed, 72 insertions(+), 45 deletions(-) diff --git a/lib/graphql/types.ts b/lib/graphql/types.ts index a960c540..6ad4fc4e 100644 --- a/lib/graphql/types.ts +++ b/lib/graphql/types.ts @@ -182,6 +182,9 @@ export type ApplicationsReportColumn = | 'PAYMENT_METHOD' | 'FEE_AMOUNT' | 'DONATION_AMOUNT' + | 'SECOND_PAYMENT_METHOD' + | 'SECOND_FEE_AMOUNT' + | 'SECOND_DONATION_AMOUNT' | 'TOTAL_AMOUNT'; export type ApplicationsResult = { @@ -944,6 +947,7 @@ export type PermitHoldersReportColumn = | 'USER_ID' | 'APPLICANT_NAME' | 'APPLICANT_DATE_OF_BIRTH' + | 'APPLICANT_AGE' | 'HOME_ADDRESS' | 'EMAIL' | 'PHONE_NUMBER' @@ -952,6 +956,7 @@ export type PermitHoldersReportColumn = | 'GUARDIAN_POA_ADDRESS' | 'RECENT_APP_NUMBER' | 'RECENT_APP_TYPE' + | 'RECENT_APP_EXPIRY_DATE' | 'USER_STATUS'; export type PermitStatus = diff --git a/lib/reports/resolvers.ts b/lib/reports/resolvers.ts index aa094600..53d3dbc2 100644 --- a/lib/reports/resolvers.ts +++ b/lib/reports/resolvers.ts @@ -10,7 +10,7 @@ import { PaymentType, } from '@lib/graphql/types'; import { SortOrder } from '@tools/types'; -import { formatFullName, formatPhoneNumber, formatPostalCode } from '@lib/utils/format'; // Formatting utils +import { formatAddress, formatFullName, formatPhoneNumber } from '@lib/utils/format'; // Formatting utils import { formatDateTimeYYYYMMDDHHMMSS, formatDateYYYYMMDD, @@ -91,6 +91,7 @@ export const generatePermitHoldersReport: Resolver< select: { rcdPermitId: true, type: true, + expiryDate: true, }, }, }, @@ -103,8 +104,12 @@ export const generatePermitHoldersReport: Resolver< firstName, middleName, lastName, - postalCode, dateOfBirth, + addressLine1, + addressLine2, + city, + province, + postalCode, guardian, permits, phone, @@ -113,36 +118,33 @@ export const generatePermitHoldersReport: Resolver< return { ...applicant, id, - phone: formatPhoneNumber(phone), - dateOfBirth: formatDateYYYYMMDD(dateOfBirth), applicantName: formatFullName(firstName, middleName, lastName), - postalCode: formatPostalCode(postalCode), + dateOfBirth: formatDateYYYYMMDD(dateOfBirth), + age: moment().diff(dateOfBirth, 'years'), + homeAddress: formatAddress(addressLine1, addressLine2, city, postalCode, province), + phone: formatPhoneNumber(phone), rcdPermitId: `#${permits[0].rcdPermitId}`, permitType: permits[0].type, + permitExpiryDate: formatDateYYYYMMDD(permits[0].expiryDate), guardianRelationship: guardian?.relationship, guardianPOAName: guardian && formatFullName(guardian.firstName, guardian.middleName, guardian.lastName), - guardianAddressLine1: guardian && guardian.addressLine1, - guardianAddressLine2: guardian && guardian.addressLine2, - guardianCity: guardian && guardian.city, - guardianPostalCode: - guardian && guardian.postalCode && formatPostalCode(guardian.postalCode), - guardianProvince: guardian && guardian.province, + guardianAddress: + guardian && + formatAddress( + guardian.addressLine1, + guardian.addressLine2, + guardian.city, + guardian.postalCode, + guardian.province + ), }; } ); - 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 }); - } - } - } + const csvHeaders = PERMIT_HOLDERS_COLUMNS.filter(({ value }) => columnsSet.has(value)).map( + ({ name, reportColumnId }) => ({ id: reportColumnId, title: name }) + ); // Generate CSV string from csv object. const csvStringifier = createObjectCsvStringifier({ @@ -275,8 +277,10 @@ export const generateApplicationsReport: Resolver< dateOfBirth: dateOfBirth && formatDateYYYYMMDD(dateOfBirth), applicationDate: createdAt ? formatDateYYYYMMDDLocal(createdAt, true) : null, applicantName: formatFullName(firstName, middleName, lastName), - processingFee: `$${Prisma.Decimal.add(processingFee, secondProcessingFee || 0)}`, - donationAmount: `$${Prisma.Decimal.add(donationAmount, secondDonationAmount || 0)}`, + processingFee: `$${processingFee}`, + donationAmount: `$${donationAmount}`, + secondProcessingFee: `$${secondProcessingFee || 0}`, + secondDonationAmount: `$${secondDonationAmount || 0}`, totalAmount: `$${Prisma.Decimal.add( Prisma.Decimal.add(processingFee, donationAmount), Prisma.Decimal.add(secondProcessingFee || 0, secondDonationAmount || 0) diff --git a/lib/reports/schema.ts b/lib/reports/schema.ts index 43d9ebca..fabea744 100644 --- a/lib/reports/schema.ts +++ b/lib/reports/schema.ts @@ -29,6 +29,9 @@ export default gql` PAYMENT_METHOD FEE_AMOUNT DONATION_AMOUNT + SECOND_PAYMENT_METHOD + SECOND_FEE_AMOUNT + SECOND_DONATION_AMOUNT TOTAL_AMOUNT } @@ -50,6 +53,7 @@ export default gql` USER_ID APPLICANT_NAME APPLICANT_DATE_OF_BIRTH + APPLICANT_AGE HOME_ADDRESS EMAIL PHONE_NUMBER @@ -58,6 +62,7 @@ export default gql` GUARDIAN_POA_ADDRESS RECENT_APP_NUMBER RECENT_APP_TYPE + RECENT_APP_EXPIRY_DATE USER_STATUS } diff --git a/lib/utils/format.ts b/lib/utils/format.ts index 356b15d4..684eb1e4 100644 --- a/lib/utils/format.ts +++ b/lib/utils/format.ts @@ -75,7 +75,7 @@ export const formatStreetAddress = (addressLine1: string, addressLine2: string | * @param postalCode Postal code * @param province Province (optional) * @param country Country (optional) - * @returns Formatted Canadian address + * @returns Formatted Canadian address in one line */ export const formatAddress = ( addressLine1: string, @@ -85,9 +85,9 @@ export const formatAddress = ( province?: Province, country?: string ): string => { - return `${addressLine2 ? `${addressLine2} - ${addressLine1}` : addressLine1} -${province ? `${city} ${province}` : city} -${country || ''} -${postalCode} - `; + const streetAddress = formatStreetAddress(addressLine1, addressLine2); + const postalCodeFormatted = formatPostalCode(postalCode); + const provinceFormatted = province ? `, ${province}` : ''; + const countryFormatted = country ? `, ${country}` : ''; + return `${streetAddress}, ${city}${provinceFormatted} ${postalCodeFormatted}${countryFormatted}`; }; diff --git a/tools/admin/reports.ts b/tools/admin/reports.ts index fa2e685c..54253e45 100644 --- a/tools/admin/reports.ts +++ b/tools/admin/reports.ts @@ -54,6 +54,21 @@ export const APPLICATIONS_COLUMNS: Array<{ value: 'DONATION_AMOUNT', reportColumnId: 'donationAmount', }, + { + name: 'Second Payment Method', + value: 'SECOND_PAYMENT_METHOD', + reportColumnId: 'secondPaymentMethod', + }, + { + name: 'Second Fee Amount', + value: 'SECOND_FEE_AMOUNT', + reportColumnId: 'secondProcessingFee', + }, + { + name: 'Second Donation Amount', + value: 'SECOND_DONATION_AMOUNT', + reportColumnId: 'secondDonationAmount', + }, { name: 'Total Amount', value: 'TOTAL_AMOUNT', @@ -65,7 +80,7 @@ export const APPLICATIONS_COLUMNS: Array<{ export const PERMIT_HOLDERS_COLUMNS: Array<{ name: string; value: PermitHoldersReportColumn; - reportColumnId: string | Array<[string, string]>; + reportColumnId: string; }> = [ { name: 'User ID', @@ -82,16 +97,15 @@ export const PERMIT_HOLDERS_COLUMNS: Array<{ value: 'APPLICANT_DATE_OF_BIRTH', reportColumnId: 'dateOfBirth', }, + { + name: 'Applicant Age', + value: 'APPLICANT_AGE', + reportColumnId: 'age', + }, { name: 'Home Address', value: 'HOME_ADDRESS', - reportColumnId: [ - ['Address Line 1', 'addressLine1'], - ['Address Line 2', 'addressLine2'], - ['City', 'city'], - ['Province', 'province'], - ['Postal Code', 'postalCode'], - ], + reportColumnId: 'homeAddress', }, { name: 'Email', @@ -116,13 +130,7 @@ export const PERMIT_HOLDERS_COLUMNS: Array<{ { name: 'Guardian/POA Address', value: 'GUARDIAN_POA_ADDRESS', - reportColumnId: [ - ['Guardian/POA Address Line 1', 'guardianAddressLine1'], - ['Guardian/POA Address Line 2', 'guardianAddressLine2'], - ['Guardian/POA City', 'guardianCity'], - ['Guardian/POA Province', 'guardianProvince'], - ['Guardian/POA Postal Code', 'guardianPostalCode'], - ], + reportColumnId: 'guardianAddress', }, { name: 'Recent APP Number', @@ -134,6 +142,11 @@ export const PERMIT_HOLDERS_COLUMNS: Array<{ value: 'RECENT_APP_TYPE', reportColumnId: 'permitType', }, + { + name: 'Recent APP Expiry Date', + value: 'RECENT_APP_EXPIRY_DATE', + reportColumnId: 'permitExpiryDate', + }, { name: 'User Status', value: 'USER_STATUS',