Skip to content

Commit 6f589c4

Browse files
committed
Remove branch you can't get to
1 parent f202e86 commit 6f589c4

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

__tests__/formatItem.unit.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ DefaultTable.entities = new Entity({
2828
list_alias2: { type: 'list', map: 'list2' },
2929
test: 'map',
3030
linked1: ['sk',0, { save: false }],
31-
linked2: ['sk',1, { save: false }]
31+
linked2: ['sk',1, { save: false }],
32+
composite: { type: 'string', alias: 'composite_alias' },
33+
linked_alias1: ['composite',0, { save: false, alias: 'linked_alias_one' }],
34+
linked_alias2: ['composite',1, { save: false, alias: 'linked_alias_two' }],
3235
}
3336
})
3437

@@ -83,6 +86,11 @@ describe('formatItem', () => {
8386
expect(result).toEqual({ linked1: 'test1' })
8487
})
8588

89+
it('formats item with linked aliased fields', () => {
90+
let result = formatItem(DocumentClient)(DefaultTable.User.schema.attributes,DefaultTable.User.linked,{ composite: 'test1#test2' })
91+
expect(result).toEqual({ composite_alias: 'test1#test2', linked_alias_one: 'test1', linked_alias_two: 'test2' })
92+
})
93+
8694
it('passes through attribute not specified in entity', () => {
8795
let result = formatItem(DocumentClient)(DefaultTable.User.schema.attributes,DefaultTable.User.linked,{ unspecified: 'value' })
8896
expect(result).toEqual({ unspecified: 'value' })

lib/formatItem.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ module.exports = (DocumentClient) => (attributes,linked,item,include=[]) => {
1818
const validateType = validateTypes(DocumentClient)
1919

2020
return Object.keys(item).reduce((acc,field) => {
21-
22-
if (linked[field] || attributes[field] && linked[attributes[field]] && linked[attributes[field]].alias) {
23-
Object.assign(acc, (linked[field] || linked[attributes[field].alias]).reduce((acc,f,i) => {
21+
if (linked[field]) {
22+
Object.assign(acc, (linked[field]).reduce((acc,f,i) => {
2423
if (attributes[f].save || attributes[f].hidden || (include.length > 0 && !include.includes(f))) return acc
2524
return Object.assign(acc,{
2625
[attributes[f].alias || f]: validateType(attributes[f],f,

0 commit comments

Comments
 (0)