Skip to content

Commit

Permalink
Merge pull request #400 from USEPA/feature/update-new-2023-prf-orgs-l…
Browse files Browse the repository at this point in the history
…ogic

Feature/update new 2023 prf orgs logic
  • Loading branch information
courtneymyers authored Mar 27, 2024
2 parents ad6db61 + 3b45afd commit 7907274
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 43 deletions.
5 changes: 5 additions & 0 deletions app/server/app/utilities/bap.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ const { submissionPeriodOpen } = require("../config/formio");
* @typedef {Object} BapDataFor2023PRF
* @property {{
* Id: string
* CSB_Snapshot__r: {
* JSON_Snapshot__c: string
* }
* Primary_Applicant__r: {
* FirstName: string
* LastName: string
Expand Down Expand Up @@ -825,6 +828,7 @@ async function queryBapFor2023PRFData(req, frfReviewItemId) {

// `SELECT
// Id,
// CSB_Snapshot__r.JSON_Snapshot__c
// Primary_Applicant__r.FirstName,
// Primary_Applicant__r.LastName,
// Primary_Applicant__r.Title,
Expand Down Expand Up @@ -869,6 +873,7 @@ async function queryBapFor2023PRFData(req, frfReviewItemId) {
{
// "*": 1,
Id: 1, // Salesforce record ID
"CSB_Snapshot__r.JSON_Snapshot__c": 1,
"Primary_Applicant__r.FirstName": 1,
"Primary_Applicant__r.LastName": 1,
"Primary_Applicant__r.Title": 1,
Expand Down
98 changes: 55 additions & 43 deletions app/server/app/utilities/formio.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function fetchDataForPRFSubmission({ rebateYear, req, res }) {
const newBusOwnerType = "New Bus Owner";

const {
CSB_Snapshot__r,
Primary_Applicant__r,
Alternate_Applicant__r,
CSB_School_District__r,
Expand All @@ -195,12 +196,14 @@ function fetchDataForPRFSubmission({ rebateYear, req, res }) {
Prioritized_as_Rural__c,
} = frf2023RecordQuery[0];

const frf2023RecordJson = JSON.parse(CSB_Snapshot__r.JSON_Snapshot__c);

const [schoolDistrictStreetAddress1, schoolDistrictStreetAddress2] = (
CSB_School_District__r?.BillingStreet ?? "\n"
).split("\n");

const org_organizations = frf2023BusRecordsContactsOrgsQueries.map(
(frf2023BusRecordsContactsOrgs) => {
const org_organizations = frf2023BusRecordsContactsOrgsQueries.reduce(
(array, frf2023BusRecordsContactsOrgs) => {
const {
Id,
Name,
Expand All @@ -211,50 +214,59 @@ function fetchDataForPRFSubmission({ rebateYear, req, res }) {
BillingPostalCode,
} = frf2023BusRecordsContactsOrgs;

const [orgStreetAddress1, orgStreetAddress2] = (
BillingStreet ?? "\n"
).split("\n");

const orgContacts = frf2023BusRecordsContactsQueries.filter(
(item) => item.Contact__r.AccountId === Id,
);

const existingBusOwner = orgContacts.some(
(item) => item.Relationship_Type__c === existingBusOwnerType,
);

const newBusOwner = orgContacts.some(
(item) => item.Relationship_Type__c === newBusOwnerType,
const jsonOrg = frf2023RecordJson.data.organizations.find(
(item) => item.org_orgName === Name,
);

const { FirstName, LastName, Title, Email, Phone } =
orgContacts[0].Contact__r ?? {};

return {
org_number: null,
org_type: {
existingBusOwner,
newBusOwner,
// privateFleet: false,
},
// _org_typeCombined: "", // NOTE: 'Existing Bus Owner, New Bus Owner'
org_orgName: Name,
org_contactFName: FirstName,
org_contactLName: LastName,
org_contactTitle: Title,
org_contactEmail: Email,
org_contactPhone: Phone,
org_address1: orgStreetAddress1,
org_address2: orgStreetAddress2,
org_county: BillingCountry,
org_city: BillingCity,
org_state: {
name: BillingState,
// abbreviation: "",
},
org_zip: BillingPostalCode,
};
if (jsonOrg) {
const [orgStreetAddress1, orgStreetAddress2] = (
BillingStreet ?? "\n"
).split("\n");

const orgContacts = frf2023BusRecordsContactsQueries.filter(
(item) => item.Contact__r.AccountId === Id,
);

const existingBusOwner = orgContacts.some(
(item) => item.Relationship_Type__c === existingBusOwnerType,
);

const newBusOwner = orgContacts.some(
(item) => item.Relationship_Type__c === newBusOwnerType,
);

const { FirstName, LastName, Title, Email, Phone } =
orgContacts[0].Contact__r ?? {};

array.push({
org_number: jsonOrg.org_number,
org_type: {
existingBusOwner,
newBusOwner,
// privateFleet: false,
},
// _org_typeCombined: "", // NOTE: 'Existing Bus Owner, New Bus Owner'
org_orgName: Name,
org_contactFName: FirstName,
org_contactLName: LastName,
org_contactTitle: Title,
org_contactEmail: Email,
org_contactPhone: Phone,
org_address1: orgStreetAddress1,
org_address2: orgStreetAddress2,
org_county: BillingCountry,
org_city: BillingCity,
org_state: {
name: BillingState,
// abbreviation: "",
},
org_zip: BillingPostalCode,
});
}

return array;
},
[],
);

const bus_buses = frf2023BusRecordsQuery.map((frf2023BusRecord) => {
Expand Down

0 comments on commit 7907274

Please sign in to comment.