1
1
import GetEntities from '@js-entity-repos/core/dist/signatures/GetEntities' ;
2
2
import Entity from '@js-entity-repos/core/dist/types/Entity' ;
3
+ import Pagination from '@js-entity-repos/core/dist/types/Pagination' ;
4
+ import { forward } from '@js-entity-repos/core/dist/types/PaginationDirection' ;
3
5
import Sort from '@js-entity-repos/core/dist/types/Sort' ;
6
+ import SortOrder , { asc } from '@js-entity-repos/core/dist/types/SortOrder' ;
4
7
import createCursorFromEntity from '@js-entity-repos/core/dist/utils/createCursorFromEntity' ;
5
8
import createPaginationFilter from '@js-entity-repos/core/dist/utils/createPaginationFilter' ;
6
9
import { first , last , mapValues } from 'lodash' ;
@@ -11,21 +14,21 @@ const xor = (conditionA: boolean, conditionB: boolean) => {
11
14
} ;
12
15
13
16
export default < E extends Entity > ( config : FacadeConfig < E > ) : GetEntities < E > => {
14
- const defaultPagination = {
17
+ const defaultPagination : Pagination = {
15
18
cursor : undefined ,
16
- forward : true ,
19
+ direction : forward ,
17
20
limit : config . defaultPaginationLimit ,
18
21
} ;
19
- const defaultSort = { id : true } as Sort < E > ;
22
+ const defaultSort = { id : asc } as Sort < E > ;
20
23
return async ( { filter = { } , sort = defaultSort , pagination = defaultPagination } ) => {
21
24
const collection = ( await config . collection ( ) ) ;
22
25
23
26
const paginationFilter = createPaginationFilter ( pagination , sort ) ;
24
27
const fullFilter = { $and : [ filter , paginationFilter ] } ;
25
28
const constructedFilter = config . constructFilter ( fullFilter ) ;
26
29
const constructedSort = config . constructSort ( sort ) ;
27
- const mongoSort = mapValues ( constructedSort , ( sortValue : boolean ) => {
28
- return ! xor ( pagination . forward , sortValue ) ? 1 : - 1 ;
30
+ const mongoSort = mapValues ( constructedSort , ( sortOrder : SortOrder ) => {
31
+ return ! xor ( pagination . direction === forward , sortOrder === asc ) ? 1 : - 1 ;
29
32
} ) ;
30
33
31
34
const documents = await collection
0 commit comments