Skip to content

Commit 37cc020

Browse files
authored
Merge pull request feathersjs-ecosystem#431 from dekelev/keep-query-fix
Added `keepQuery` support for keeping props with dot in their name
2 parents ebcdb1e + 2469958 commit 37cc020

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/common/_pluck.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ function _pluckItem (item, fieldNames) {
2020
const plucked = {};
2121

2222
fieldNames.forEach(fieldName => {
23-
const value = getByDot(item, fieldName);
23+
const value = fieldName in item ? item[fieldName] : getByDot(item, fieldName);
2424
if (value !== undefined) { // prevent setByDot creating nested empty objects
25-
setByDot(plucked, fieldName, value);
25+
if (fieldName in item) { plucked[fieldName] = value; } else { setByDot(plucked, fieldName, value); }
2626
}
2727
});
2828

tests/services/keep-query.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('services keepQuery', () => {
4343
type: 'before',
4444
method: 'create',
4545
params: {
46-
query: { empl: { name: { first: 'John', last: 'Doe' }, status: 'AA' }, dept: 'Acct' }
46+
query: { empl: { name: { first: 'John', last: 'Doe' }, status: 'AA' }, dept: 'Acct', 'owner.id': 1, 'owner.admin': false }
4747
} };
4848
});
4949

@@ -55,9 +55,9 @@ describe('services keepQuery', () => {
5555
});
5656

5757
it('prop with 1 dot', () => {
58-
hooks.keepQuery('empl.name', 'dept')(hookBefore);
58+
hooks.keepQuery('empl.name', 'dept', 'owner.id', 'owner.admin')(hookBefore);
5959
assert.deepEqual(hookBefore.params.query,
60-
{ empl: { name: { first: 'John', last: 'Doe' } }, dept: 'Acct' }
60+
{ empl: { name: { first: 'John', last: 'Doe' } }, dept: 'Acct', 'owner.id': 1, 'owner.admin': false }
6161
);
6262
});
6363

0 commit comments

Comments
 (0)