@@ -4,9 +4,9 @@ import Pagination from '@js-entity-repos/core/dist/types/Pagination';
4
4
import { forward } from '@js-entity-repos/core/dist/types/PaginationDirection' ;
5
5
import Sort from '@js-entity-repos/core/dist/types/Sort' ;
6
6
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 ' ;
8
8
import createPaginationFilter from '@js-entity-repos/core/dist/utils/createPaginationFilter' ;
9
- import { first , last , mapValues } from 'lodash' ;
9
+ import { mapValues } from 'lodash' ;
10
10
import FacadeConfig from '../FacadeConfig' ;
11
11
12
12
const xor = ( conditionA : boolean , conditionB : boolean ) => {
@@ -32,16 +32,16 @@ export default <E extends Entity>(config: FacadeConfig<E>): GetEntities<E> => {
32
32
return ! xor ( pagination . direction === forward , sortOrder === asc ) ? 1 : - 1 ;
33
33
} ) ;
34
34
35
- const documents = await collection
35
+ const results = await collection
36
36
. find ( constructedFilter )
37
37
. sort ( mongoSort )
38
- . limit ( pagination . limit )
38
+ . limit ( pagination . limit + 1 )
39
39
. toArray ( ) ;
40
+ const documents = results . slice ( 0 , pagination . limit ) ;
40
41
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 ;
44
44
45
- return { entities, nextCursor , previousCursor } ;
45
+ return createGetEntitiesResult ( { entities, isEnd , pagination , sort } ) ;
46
46
} ;
47
47
} ;
0 commit comments