Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 21 additions & 1 deletion src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,25 @@ function bigIntToNumber (value) {
return null
}

function convertBigIntDeep (value) {
if (value === null || value === undefined) {
return value
}
if (typeof value === 'bigint') {
return bigIntToNumber(value)
}
if (Array.isArray(value)) {
return value.map(convertBigIntDeep)
}
if (value instanceof Date) {
return value
}
if (typeof value === 'object') {
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
Using _.mapValues on an object without checking for circular references can lead to a stack overflow error if the object contains circular references. Consider adding a check to handle such cases.

return _.mapValues(value, convertBigIntDeep)
}
return value
}

module.exports = {
wrapExpress,
autoWrapExpress,
Expand Down Expand Up @@ -591,5 +610,6 @@ module.exports = {
getParamsFromQueryAsArray,
secureMemberAddressData,
truncateLastName,
bigIntToNumber
bigIntToNumber,
convertBigIntDeep
}
2 changes: 1 addition & 1 deletion src/services/MemberTraitService.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ async function getTraits (currentUser, handle, query) {
if (!currentUser) {
result = _.filter(result, (item) => _.includes(config.MEMBER_PUBLIC_TRAITS, item.traitId))
}
return result
return helper.convertBigIntDeep(result)
Copy link

Choose a reason for hiding this comment

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

[⚠️ correctness]
The function helper.convertBigIntDeep(result) is used to convert BigInt values deeply within the result object. Ensure that this conversion is necessary for all elements within result and that helper.convertBigIntDeep handles all edge cases correctly, especially if result can contain nested structures or unexpected data types.

}

getTraits.schema = {
Expand Down