@@ -14,7 +14,7 @@ const getContext = (context: HookContext) => {
1414}
1515
1616export const resolveQuery = < T > ( resolver : Resolver < T , HookContext > ) =>
17- async ( context : HookContext , next : NextFunction ) => {
17+ async ( context : HookContext , next ? : NextFunction ) => {
1818 const ctx = getContext ( context ) ;
1919 const data = context ?. params ?. query || { } ;
2020 const query = await resolver . resolve ( data , ctx , {
@@ -26,11 +26,13 @@ export const resolveQuery = <T> (resolver: Resolver<T, HookContext>) =>
2626 query
2727 }
2828
29- return next ( ) ;
29+ if ( typeof next === 'function' ) {
30+ return next ( ) ;
31+ }
3032 } ;
3133
3234export const resolveData = < T > ( resolver : Resolver < T , HookContext > ) =>
33- async ( context : HookContext , next : NextFunction ) => {
35+ async ( context : HookContext , next ? : NextFunction ) => {
3436 const ctx = getContext ( context ) ;
3537 const data = context . data ;
3638 const status = {
@@ -45,27 +47,32 @@ export const resolveData = <T> (resolver: Resolver<T, HookContext>) =>
4547 context . data = await resolver . resolve ( data , ctx , status ) ;
4648 }
4749
48- return next ( ) ;
50+ if ( typeof next === 'function' ) {
51+ return next ( ) ;
52+ }
4953 } ;
5054
5155export const resolveResult = < T > ( resolver : Resolver < T , HookContext > ) =>
52- async ( context : HookContext , next : NextFunction ) => {
53- const { $resolve : properties , ... query } = context . params ?. query || { } ;
54- const { resolve } = context . params ;
55- const status = {
56- originalContext : context ,
57- .. .resolve ,
58- properties
59- } ;
56+ async ( context : HookContext , next ? : NextFunction ) => {
57+ if ( typeof next === 'function' ) {
58+ const { $ resolve: properties , ... query } = context . params ?. query || { } ;
59+ const resolve = {
60+ originalContext : context ,
61+ ... context . params . resolve ,
62+ properties
63+ } ;
6064
61- context . params = {
62- ...context . params ,
63- query
64- }
65+ context . params = {
66+ ...context . params ,
67+ resolve,
68+ query
69+ }
6570
66- await next ( ) ;
71+ await next ( ) ;
72+ }
6773
6874 const ctx = getContext ( context ) ;
75+ const status = context . params . resolve ;
6976 const data = context . method === 'find' && context . result . data
7077 ? context . result . data
7178 : context . result ;
@@ -80,7 +87,7 @@ export const resolveResult = <T> (resolver: Resolver<T, HookContext>) =>
8087 } ;
8188
8289export const validateQuery = ( schema : Schema < any > ) =>
83- async ( context : HookContext , next : NextFunction ) => {
90+ async ( context : HookContext , next ? : NextFunction ) => {
8491 const data = context ?. params ?. query || { } ;
8592
8693 try {
@@ -91,14 +98,16 @@ export const validateQuery = (schema: Schema<any>) =>
9198 query
9299 }
93100
94- return next ( ) ;
101+ if ( typeof next === 'function' ) {
102+ return next ( ) ;
103+ }
95104 } catch ( error : any ) {
96105 throw ( error . ajv ? new BadRequest ( error . message , error . errors ) : error ) ;
97106 }
98107 } ;
99108
100109export const validateData = ( schema : Schema < any > ) =>
101- async ( context : HookContext , next : NextFunction ) => {
110+ async ( context : HookContext , next ? : NextFunction ) => {
102111 const data = context . data ;
103112
104113 try {
@@ -113,5 +122,7 @@ export const validateData = (schema: Schema<any>) =>
113122 throw ( error . ajv ? new BadRequest ( error . message , error . errors ) : error ) ;
114123 }
115124
116- return next ( ) ;
125+ if ( typeof next === 'function' ) {
126+ return next ( ) ;
127+ }
117128 } ;
0 commit comments