Skip to content

Commit

Permalink
fixed district router sometimes failing on .find()
Browse files Browse the repository at this point in the history
  • Loading branch information
suzalflueck committed Apr 23, 2024
1 parent 2e22a9e commit 761d80d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions backend/src/components/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function removeFieldsByCriteria(inputData, criteria) {
}
function appendMailingAddressDetailsAndRemoveAddresses(data) {
if (data && data.addresses && data.addresses.length > 0) {
const physicalAddress = data.addresses.find(
const physicalAddress = data.addresses?.find(
(address) => address.addressTypeCode === "PHYSICAL"
);
if (physicalAddress) {
Expand All @@ -101,7 +101,7 @@ function appendMailingAddressDetailsAndRemoveAddresses(data) {

// Remove the "addresses" property
}
const courierAddress = data.addresses.find(
const courierAddress = data.addresses?.find(
(address) => address.addressTypeCode === "MAILING"
);
if (courierAddress) {
Expand Down Expand Up @@ -132,7 +132,7 @@ function appendMailingAddressDetailsAndRemoveAddresses(data) {
function addDistrictLabels(jsonData, districtList) {
if (jsonData.content && Array.isArray(jsonData.content)) {
jsonData.content.forEach((dataItem) => {
const district = districtList.find(
const district = districtList?.find(
(item) => item.districtId === dataItem.districtId
);
if (district) {
Expand Down Expand Up @@ -229,7 +229,7 @@ function normalizeJsonObject(
includeFields
) {
return sourceArray.map((item) => {
const matchingItem = referenceArray.find(
const matchingItem = referenceArray?.find(
(info) =>
info[matchKey] === item[matchKey] && (!condition || condition(info))
);
Expand Down Expand Up @@ -402,7 +402,7 @@ function createSchoolCache(schoolData, schoolGrades) {
});

// Extract and format principal contact information if it exists
const principalContact = school.contacts.find(
const principalContact = school.contacts?.find(
(contact) => contact.schoolContactTypeCode === "PRINCIPAL"
);
if (principalContact) {
Expand Down

0 comments on commit 761d80d

Please sign in to comment.