@@ -2,31 +2,32 @@ import { Provider } from '@nestjs/common';
2
2
import { Class } from '@rezonate/nestjs-query-core' ;
3
3
4
4
import { createDefaultAuthorizer , getAuthorizerToken , getCustomAuthorizerToken } from '../auth' ;
5
- import { getAuthorizer , getCustomAuthorizer } from '../decorators' ;
5
+ import { getAuthorizer , getCustomAuthorizer , setHasAuthorizerProvider } from '../decorators' ;
6
6
7
7
function createServiceProvider < DTO > ( DTOClass : Class < DTO > ) : Provider {
8
- const token = getAuthorizerToken ( DTOClass ) ;
9
- const authorizer = getAuthorizer ( DTOClass ) ;
10
- if ( ! authorizer ) {
11
- // create default authorizer in case any relations have an authorizers
12
- return { provide : token , useClass : createDefaultAuthorizer ( DTOClass , { authorize : ( ) => ( { } ) } ) } ;
13
- }
14
- return { provide : token , useClass : authorizer } ;
8
+ const token = getAuthorizerToken ( DTOClass ) ;
9
+ const authorizer = getAuthorizer ( DTOClass ) ;
10
+ setHasAuthorizerProvider ( DTOClass ) ;
11
+ if ( ! authorizer ) {
12
+ // create default authorizer in case any relations have an authorizers
13
+ return { provide : token , useClass : createDefaultAuthorizer ( DTOClass , { authorize : ( ) => ( { } ) } ) } ;
14
+ }
15
+ return { provide : token , useClass : authorizer } ;
15
16
}
16
17
17
18
function createCustomAuthorizerProvider < DTO > ( DTOClass : Class < DTO > ) : Provider | undefined {
18
- const token = getCustomAuthorizerToken ( DTOClass ) ;
19
- const customAuthorizer = getCustomAuthorizer ( DTOClass ) ;
20
- if ( customAuthorizer ) {
21
- return { provide : token , useClass : customAuthorizer } ;
22
- }
23
- return undefined ;
19
+ const token = getCustomAuthorizerToken ( DTOClass ) ;
20
+ const customAuthorizer = getCustomAuthorizer ( DTOClass ) ;
21
+ if ( customAuthorizer ) {
22
+ return { provide : token , useClass : customAuthorizer } ;
23
+ }
24
+ return undefined ;
24
25
}
25
26
26
27
export const createAuthorizerProviders = ( DTOClasses : Class < unknown > [ ] ) : Provider [ ] =>
27
- DTOClasses . reduce < Provider [ ] > ( ( providers , DTOClass ) => {
28
- const p = createCustomAuthorizerProvider ( DTOClass ) ;
29
- if ( p ) providers . push ( p ) ;
30
- providers . push ( createServiceProvider ( DTOClass ) ) ;
31
- return providers ;
32
- } , [ ] ) ;
28
+ DTOClasses . reduce < Provider [ ] > ( ( providers , DTOClass ) => {
29
+ const p = createCustomAuthorizerProvider ( DTOClass ) ;
30
+ if ( p ) providers . push ( p ) ;
31
+ providers . push ( createServiceProvider ( DTOClass ) ) ;
32
+ return providers ;
33
+ } , [ ] ) ;
0 commit comments