Skip to content

Commit

Permalink
fix(crud): Do not return pageCount field when alwaysPaginate
Browse files Browse the repository at this point in the history
  • Loading branch information
debagger committed Apr 11, 2020
1 parent ece8c5a commit 2421b79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 2 additions & 6 deletions packages/crud/src/services/crud-service.abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,8 @@ export abstract class CrudService<T> {
data,
count: data.length,
total,
page: Math.floor(offset / limit) + 1,
pageCount:
limit && total
? Math.ceil(total / limit)
: /* istanbul ignore next line */
undefined,
page: limit ? Math.floor(offset / limit) + 1 : 1,
pageCount: limit && total ? Math.ceil(total / limit) : 1,
};
}

Expand Down
13 changes: 13 additions & 0 deletions packages/crud/test/crud-service.abstract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ describe('#crud', () => {
};
expect(service.createPageInfo([], 100, 10, 10)).toMatchObject(expected);
});

it('should return an object when limit and offset undefined', () => {
const expected = {
count: 0,
data: [],
page: 1,
pageCount: 1,
total: 100,
};
expect(service.createPageInfo([], 100, undefined, undefined)).toMatchObject(
expected,
);
});
});
});
});

0 comments on commit 2421b79

Please sign in to comment.