@@ -2,29 +2,30 @@ import Entity from '@js-entity-repos/core/dist/types/Entity';
2
2
import { Request , Response } from 'express' ;
3
3
import { OK } from 'http-status-codes' ;
4
4
import FacadeConfig from '../FacadeConfig' ;
5
- import catchErrors from '../utils/catchErrors' ;
6
5
import getJsonQueryParam from '../utils/getJsonQueryParam' ;
7
6
import getNumberQueryParam from '../utils/getNumberQueryParam' ;
8
7
9
8
export default < E extends Entity > ( config : FacadeConfig < E > ) => {
10
- return catchErrors ( async ( req : Request , res : Response ) => {
11
- const limit = getNumberQueryParam ( req . query , 'limit' , config . defaultPaginationLimit ) ;
12
- const result = await config . service . getEntities ( {
13
- filter : config . constructFilter ( getJsonQueryParam ( req . query , 'filter' ) ) ,
14
- pagination : {
15
- cursor : req . query . cursor ,
16
- forward : req . query . forward === 'true' ,
17
- limit,
18
- } ,
19
- sort : getJsonQueryParam ( req . query , 'sort' ) ,
9
+ return async ( req : Request , res : Response ) => {
10
+ await config . handleTransaction ( { req, res } , async ( ) => {
11
+ const limit = getNumberQueryParam ( req . query , 'limit' , config . defaultPaginationLimit ) ;
12
+ const result = await config . service . getEntities ( {
13
+ filter : config . constructFilter ( getJsonQueryParam ( req . query , 'filter' ) ) ,
14
+ pagination : {
15
+ cursor : req . query . cursor ,
16
+ forward : req . query . forward === 'true' ,
17
+ limit,
18
+ } ,
19
+ sort : getJsonQueryParam ( req . query , 'sort' ) ,
20
+ } ) ;
21
+ res . status ( OK ) ;
22
+ if ( result . nextCursor !== undefined ) {
23
+ res . setHeader ( 'x-entities-next-cursor' , result . nextCursor ) ;
24
+ }
25
+ if ( result . previousCursor !== undefined ) {
26
+ res . setHeader ( 'x-entities-previous-cursor' , result . previousCursor ) ;
27
+ }
28
+ res . json ( result . entities ) ;
20
29
} ) ;
21
- res . status ( OK ) ;
22
- if ( result . nextCursor !== undefined ) {
23
- res . setHeader ( 'x-entities-next-cursor' , result . nextCursor ) ;
24
- }
25
- if ( result . previousCursor !== undefined ) {
26
- res . setHeader ( 'x-entities-previous-cursor' , result . previousCursor ) ;
27
- }
28
- res . json ( result . entities ) ;
29
- } ) ;
30
+ } ;
30
31
} ;
0 commit comments