Skip to content

Commit

Permalink
Added a check on result when using $modify with pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekel Barzilay committed Jun 19, 2020
1 parent de3f17e commit 0da171b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ class Service extends AdapterService {
this.objectify(countQuery, query, null, null, query.$allowRefs);

return countQuery
.then(count => parseInt(count[0].total, 10))
.then(count => count && count.length ? parseInt(count[0].total, 10) : 0)
.then(executeQuery)
.catch(errorHandler);
}
Expand Down
3 changes: 2 additions & 1 deletion test/company.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export default class Company extends Model {
builder.orderBy('name');
},
google: (builder, hasCeo) => {
builder.where('name', 'Google');
builder.where('name', 'Google')
.groupBy(['name']);

if (hasCeo) { builder.whereNot('ceo', null); }
},
Expand Down
15 changes: 14 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,8 @@ describe('Feathers Objection Service', () => {
.create([
{
name: 'Google',
ceo: 1
ceo: 1,
size: 'medium'
},
{
name: 'Apple',
Expand Down Expand Up @@ -1744,6 +1745,18 @@ describe('Feathers Objection Service', () => {
});
});

it('allow $modify query with paginate and no results', () => {
companies.options.paginate = {
default: 1,
max: 2
};

return companies.find({ query: { $modify: ['google'], size: 'small' } }).then(data => {
expect(data.total).to.be.equal(0);
expect(data.data.length).to.be.equal(0);
});
});

it('allow $modify query as string', () => {
return companies.find({ query: { $modify: 'google' } }).then(data => {
expect(data.length).to.be.equal(1);
Expand Down

0 comments on commit 0da171b

Please sign in to comment.