Skip to content

Commit

Permalink
Fix query mergin on patch (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Jul 7, 2019
1 parent c00103f commit 3f0163d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
10 changes: 4 additions & 6 deletions lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,13 @@ class Service extends AdapterService {
// return a promise properly when runValidators is true. WTF!
try {
return ids.then(idList => {
const { query: { $populate } = {} } = params;
// Create a new query that re-queries all ids that
// were originally changed
const findParams = idList.length ? Object.assign({}, params, {
const updatedQuery = (idList.length && id === null) ? { [this.id]: { $in: idList } } : params.query;
const findParams = Object.assign({}, params, {
paginate: false,
query: Object.assign({
[this.id]: { $in: idList }
}, params.query)
}) : Object.assign({}, params, {
paginate: false
query: $populate ? Object.assign(updatedQuery, { $populate }) : updatedQuery
});

// If params.query.$populate was provided, remove it
Expand Down
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,13 @@ describe('Feathers Mongoose Service', () => {
expect(error.name).to.equal('Conflict');
}
});

it('Returns correct result when queried properties ar patched', async () => {
const data = await pets.patch(null, { name: 'Spot' }, { query: { name: 'Rufus' } });
expect(data).to.be.an('array');
expect(data.length).to.equal(1);
expect(data[0].name).to.equal('Spot');
});
});

describe('Lean Services', () => {
Expand Down

0 comments on commit 3f0163d

Please sign in to comment.