Skip to content
This repository was archived by the owner on Jun 15, 2021. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7de69b6

Browse files
committedMar 28, 2018
fix(deps): Updates core to v9.
1 parent ada4d59 commit 7de69b6

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed
 

‎package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"check-coverage": true
2626
},
2727
"dependencies": {
28-
"@js-entity-repos/core": "^7.1.0",
28+
"@js-entity-repos/core": "^9.0.0",
2929
"lodash": "^4.17.4",
3030
"mongodb": "^3.0.0"
3131
},

‎src/functions/getEntities.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import Pagination from '@js-entity-repos/core/dist/types/Pagination';
44
import { forward } from '@js-entity-repos/core/dist/types/PaginationDirection';
55
import Sort from '@js-entity-repos/core/dist/types/Sort';
66
import SortOrder, { asc } from '@js-entity-repos/core/dist/types/SortOrder';
7-
import createCursorFromEntity from '@js-entity-repos/core/dist/utils/createCursorFromEntity';
7+
import createGetEntitiesResult from '@js-entity-repos/core/dist/utils/createGetEntitiesResult';
88
import createPaginationFilter from '@js-entity-repos/core/dist/utils/createPaginationFilter';
9-
import { first, last, mapValues } from 'lodash';
9+
import { mapValues } from 'lodash';
1010
import FacadeConfig from '../FacadeConfig';
1111

1212
const xor = (conditionA: boolean, conditionB: boolean) => {
@@ -32,16 +32,16 @@ export default <E extends Entity>(config: FacadeConfig<E>): GetEntities<E> => {
3232
return !xor(pagination.direction === forward, sortOrder === asc) ? 1 : -1;
3333
});
3434

35-
const documents = await collection
35+
const results = await collection
3636
.find(constructedFilter)
3737
.sort(mongoSort)
38-
.limit(pagination.limit)
38+
.limit(pagination.limit + 1)
3939
.toArray();
40+
const documents = results.slice(0, pagination.limit);
4041

41-
const entities = documents.map(config.constructEntity);
42-
const nextCursor = createCursorFromEntity(last(entities), sort);
43-
const previousCursor = createCursorFromEntity(first(entities), sort);
42+
const entities: E[] = documents.map(config.constructEntity);
43+
const isEnd = results.length <= pagination.limit;
4444

45-
return { entities, nextCursor, previousCursor };
45+
return createGetEntitiesResult({ entities, isEnd, pagination, sort });
4646
};
4747
};

0 commit comments

Comments
 (0)
This repository has been archived.