Skip to content

Commit

Permalink
Patch with same field in data & query now returns success result
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekel Barzilay committed May 9, 2020
1 parent 4cf8d53 commit 0daec81
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,12 @@ class Service extends AdapterService {
const selectParam = filters.$select ? { $select: filters.$select } : undefined;
const findParams = Object.assign({}, params, { query: Object.assign({}, params.query, this.getIdsQuery(id, idList), selectParam) });

for (const key of Object.keys(dataCopy)) {
if (findParams.query[key]) {
findParams.query[key] = dataCopy[key];
}
}

return q.patch(dataCopy).then(() => {
return params.query && params.query.$noSelect ? {} : this._find(findParams).then(page => {
const items = page.data || page;
Expand Down
38 changes: 38 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1785,4 +1785,42 @@ describe('Feathers Objection Service', () => {
});
});
});

describe('Patch with same field in data & query', () => {
let company;

beforeEach(async () => {
company = await companies.create({ name: 'Apple' });
});

afterEach(async () => {
await companies.remove(null);
});

it('Patch with id', () => {
return companies.patch(company.id, {
name: 'Google'
}, {
query: {
name: 'Apple'
}
}).then(data => {
expect(data).to.be.ok;
expect(data.name).to.be.equal('Google');
});
});

it('Patch without id', () => {
return companies.patch(null, {
name: 'Google'
}, {
query: {
name: 'Apple'
}
}).then(data => {
expect(data.length).to.be.equal(1);
expect(data[0].name).to.be.equal('Google');
});
});
});
});

0 comments on commit 0daec81

Please sign in to comment.