Skip to content
Open
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
7 changes: 3 additions & 4 deletions src/services/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ module.exports = class ReportsHelper {
if (result?.length) {
const transformedEntityData = await utils.mapEntityTypeToData(
result,
entityTypesDataWithPagination.result
entityTypesDataWithPagination.result || []
)
Comment on lines 463 to 466
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Defensive fallback is still incomplete — use optional chaining on the parent

In all three changed locations, .result is accessed directly on the return value of getEntityTypeWithEntitiesBasedOnOrg before the || [] guard can apply. If that call ever returns null or undefined, a TypeError is thrown before the fallback activates. The getFilterList method (line 92) consistently checks .success && .result before using the result; getReportData should be equally cautious.

🛡️ Proposed fix using optional chaining
- entityTypesDataWithPagination.result || []
+ entityTypesDataWithPagination?.result || []
- (entityTypeFilters.result || []).reduce((acc, item) => {
+ (entityTypeFilters?.result || []).reduce((acc, item) => {
- entityTypesData.result || []
+ entityTypesData?.result || []

Also applies to: 493-496, 523-526

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/services/reports.js` around lines 463 - 466, The code is accessing
.result directly on the return value of getEntityTypeWithEntitiesBasedOnOrg
(used before calling utils.mapEntityTypeToData) which can throw if that call
returns null/undefined; update the three spots in getReportData where you do
something like entityTypesDataWithPagination.result to use optional chaining on
the parent (e.g., entityTypesDataWithPagination?.result) so the || [] fallback
actually works; locate references to getEntityTypeWithEntitiesBasedOnOrg and
mapEntityTypeToData in getReportData and replace direct .result accesses with
?.result in all three changed locations (around the lines that call
utils.mapEntityTypeToData).

reportDataResult.data =
reportDataResult.report_type === common.REPORT_TABLE ? transformedEntityData : { ...result[0] }
Expand Down Expand Up @@ -490,7 +490,7 @@ module.exports = class ReportsHelper {
defaults.tenantCode
)

const filtersEntity = entityTypeFilters.result.reduce((acc, item) => {
const filtersEntity = (entityTypeFilters.result || []).reduce((acc, item) => {
acc[item.value] = item.entities
return acc
}, {})
Expand Down Expand Up @@ -520,10 +520,9 @@ module.exports = class ReportsHelper {
defaults.tenantCode
)

// Process the data
const transformedData = await utils.mapEntityTypeToData(
resultWithoutPagination,
entityTypesData.result
entityTypesData.result || []
)

const keyToLabelMap = Object.fromEntries(
Expand Down