Skip to content

Commit cef4215

Browse files
committed
Better handling of slightly messy prod data
1 parent addaedb commit cef4215

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/common/helper.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,25 @@ function bigIntToNumber (value) {
564564
return null
565565
}
566566

567+
function convertBigIntDeep (value) {
568+
if (value === null || value === undefined) {
569+
return value
570+
}
571+
if (typeof value === 'bigint') {
572+
return bigIntToNumber(value)
573+
}
574+
if (Array.isArray(value)) {
575+
return value.map(convertBigIntDeep)
576+
}
577+
if (value instanceof Date) {
578+
return value
579+
}
580+
if (typeof value === 'object') {
581+
return _.mapValues(value, convertBigIntDeep)
582+
}
583+
return value
584+
}
585+
567586
module.exports = {
568587
wrapExpress,
569588
autoWrapExpress,
@@ -591,5 +610,6 @@ module.exports = {
591610
getParamsFromQueryAsArray,
592611
secureMemberAddressData,
593612
truncateLastName,
594-
bigIntToNumber
613+
bigIntToNumber,
614+
convertBigIntDeep
595615
}

src/services/MemberTraitService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ async function getTraits (currentUser, handle, query) {
241241
if (!currentUser) {
242242
result = _.filter(result, (item) => _.includes(config.MEMBER_PUBLIC_TRAITS, item.traitId))
243243
}
244-
return result
244+
return helper.convertBigIntDeep(result)
245245
}
246246

247247
getTraits.schema = {

0 commit comments

Comments
 (0)