Skip to content

Commit f202e86

Browse files
committed
Allow attributes not specified in entity to be passed through
1 parent 2de1a1c commit f202e86

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

__tests__/formatItem.unit.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,9 @@ describe('formatItem', () => {
8383
expect(result).toEqual({ linked1: 'test1' })
8484
})
8585

86+
it('passes through attribute not specified in entity', () => {
87+
let result = formatItem(DocumentClient)(DefaultTable.User.schema.attributes,DefaultTable.User.linked,{ unspecified: 'value' })
88+
expect(result).toEqual({ unspecified: 'value' })
89+
})
90+
8691
})

lib/formatItem.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = (DocumentClient) => (attributes,linked,item,include=[]) => {
1919

2020
return Object.keys(item).reduce((acc,field) => {
2121

22-
if (linked[field] || linked[attributes[field].alias]) {
22+
if (linked[field] || attributes[field] && linked[attributes[field]] && linked[attributes[field]].alias) {
2323
Object.assign(acc, (linked[field] || linked[attributes[field].alias]).reduce((acc,f,i) => {
2424
if (attributes[f].save || attributes[f].hidden || (include.length > 0 && !include.includes(f))) return acc
2525
return Object.assign(acc,{
@@ -38,7 +38,7 @@ module.exports = (DocumentClient) => (attributes,linked,item,include=[]) => {
3838
if (attributes[field] && attributes[field].type === 'set' && Array.isArray(item[field].values)) { item[field] = item[field].values }
3939
return Object.assign(acc,{
4040
[(attributes[field] && attributes[field].alias) || field]: (
41-
attributes[field].prefix || attributes[field].suffix
41+
attributes[field] && (attributes[field].prefix || attributes[field].suffix)
4242
? item[field]
4343
.replace(new RegExp(`^${escapeRegExp(attributes[field].prefix)}`),'')
4444
.replace(new RegExp(`${escapeRegExp(attributes[field].suffix)}$`),'')

0 commit comments

Comments
 (0)