Skip to content

Commit

Permalink
Update new 2024 PRF submission data to include contact record types
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneymyers committed Jan 22, 2025
1 parent 415c707 commit 47618be
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions app/server/app/utilities/formio.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ function fetchDataForPRFSubmission({ rebateYear, req, res }) {
frf2024RecordQuery,
frf2024BusRecordsQuery,
frf2024BusRecordsContactsQueries,
frf2024ContactsRecordTypesQuery,
} = results;

const existingBusOwnerType = "Old Bus Private Fleet Owner (if changed)";
Expand Down Expand Up @@ -535,6 +536,7 @@ function fetchDataForPRFSubmission({ rebateYear, req, res }) {

const {
Id: contactId,
RecordTypeId,
FirstName,
LastName,
Title,
Expand Down Expand Up @@ -577,6 +579,10 @@ function fetchDataForPRFSubmission({ rebateYear, req, res }) {
BillingStreet ?? "\n"
).split("\n");

const orgContactRecordType = frf2024ContactsRecordTypesQuery.find(
(item) => item.Id === RecordTypeId,
);

array.push({
_bap_org_frf: true,
org_number: jsonOrg.org_number,
Expand All @@ -588,6 +594,7 @@ function fetchDataForPRFSubmission({ rebateYear, req, res }) {
_bap_org_id: orgId,
_bap_org_name: orgName,
_bap_org_contact_id_frf: contactId,
_bap_org_contact_recordtype: orgContactRecordType?.Name || "",
_bap_org_contact_fname: FirstName,
_bap_org_contact_lname: LastName,
_bap_org_contact_title: Title,
Expand Down Expand Up @@ -642,12 +649,21 @@ function fetchDataForPRFSubmission({ rebateYear, req, res }) {
item.Relationship_Type__c === newBusOwnerType,
);

const existingOwnerRecordType = frf2024ContactsRecordTypesQuery.find(
(item) => item.Id === existingOwnerRecord?.Contact__r?.RecordTypeId,
);

const newOwnerRecordType = frf2024ContactsRecordTypesQuery.find(
(item) => item.Id === newOwnerRecord?.Contact__r?.RecordTypeId,
);

return {
bus_number: Rebate_Item_num__c,
bus_existing_owner: {
org_id: existingOwnerRecord?.Contact__r?.Account?.Id,
org_name: existingOwnerRecord?.Contact__r?.Account?.Name,
org_contact_id: existingOwnerRecord?.Contact__r?.Id,
org_contact_recordtype: existingOwnerRecordType?.Name || "",
org_contact_fname: existingOwnerRecord?.Contact__r?.FirstName,
org_contact_lname: existingOwnerRecord?.Contact__r?.LastName,
},
Expand All @@ -668,6 +684,7 @@ function fetchDataForPRFSubmission({ rebateYear, req, res }) {
org_id: newOwnerRecord?.Contact__r?.Account?.Id,
org_name: newOwnerRecord?.Contact__r?.Account?.Name,
org_contact_id: newOwnerRecord?.Contact__r?.Id,
org_contact_recordtype: newOwnerRecordType?.Name || "",
org_contact_fname: newOwnerRecord?.Contact__r?.FirstName,
org_contact_lname: newOwnerRecord?.Contact__r?.LastName,
},
Expand All @@ -678,6 +695,18 @@ function fetchDataForPRFSubmission({ rebateYear, req, res }) {
};
});

const primaryContactRecordType = frf2024ContactsRecordTypesQuery.find(
(item) => item.Id === Primary_Applicant__r?.RecordTypeId,
);

const alternateContactRecordType = frf2024ContactsRecordTypesQuery.find(
(item) => item.Id === Alternate_Applicant__r?.RecordTypeId,
);

const districtContactRecordType = frf2024ContactsRecordTypesQuery.find(
(item) => item.Id === School_District_Contact__r?.RecordTypeId,
);

return {
data: {
_frf_modified: frfModified,
Expand All @@ -704,12 +733,14 @@ function fetchDataForPRFSubmission({ rebateYear, req, res }) {
_bap_govt_bus_poc_email: GOVT_BUS_POC_EMAIL__c,
_bap_alt_govt_bus_poc_email: ALT_GOVT_BUS_POC_EMAIL__c,
_bap_primary_id: Primary_Applicant__r?.Id,
_bap_primary_recordtype: primaryContactRecordType?.Name || "",
_bap_primary_fname: Primary_Applicant__r?.FirstName,
_bap_primary_lname: Primary_Applicant__r?.LastName,
_bap_primary_title: Primary_Applicant__r?.Title,
_bap_primary_email: Primary_Applicant__r?.Email,
_bap_primary_phone: Primary_Applicant__r?.Phone,
_bap_alternate_id: Alternate_Applicant__r?.Id,
_bap_alternate_recordtype: alternateContactRecordType?.Name,
_bap_alternate_fname: Alternate_Applicant__r?.FirstName,
_bap_alternate_lname: Alternate_Applicant__r?.LastName,
_bap_alternate_title: Alternate_Applicant__r?.Title,
Expand All @@ -731,6 +762,7 @@ function fetchDataForPRFSubmission({ rebateYear, req, res }) {
},
_bap_district_self_certify: Self_Certification_Category__c,
_bap_district_contact_id: School_District_Contact__r?.Id,
_bap_district_contact_recordtype: districtContactRecordType?.Name || "", // prettier-ignore
_bap_district_contact_fname: School_District_Contact__r?.FirstName,
_bap_district_contact_lname: School_District_Contact__r?.LastName,
_bap_district_contact_title: School_District_Contact__r?.Title,
Expand Down

0 comments on commit 47618be

Please sign in to comment.