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 if it's a plain object can lead to unexpected behavior if value is an instance of a class or has a prototype chain. Consider using _.isPlainObject to ensure value is a plain object before mapping its values.

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]
Ensure that helper.convertBigIntDeep is correctly handling all possible data structures within result. If result contains nested objects or arrays, verify that convertBigIntDeep can process them without errors or unintended modifications.

}

getTraits.schema = {
Expand Down
Loading