@@ -11,11 +11,9 @@ import { Pagination } from '../../shared/baseModel'
11
11
import { getPageInfo } from '../../shared/pagination'
12
12
import { Access } from '../../access/model'
13
13
14
- export const getGrants : QueryResolvers < ApolloContext > [ 'grants' ] = async (
15
- _ ,
16
- args ,
17
- ctx
18
- ) : Promise < ResolversTypes [ 'GrantsConnection' ] > => {
14
+ export const getGrants : NonNullable <
15
+ QueryResolvers < ApolloContext > [ 'grants' ]
16
+ > = async ( _ , args , ctx ) : Promise < ResolversTypes [ 'GrantsConnection' ] > => {
19
17
const grantService = await ctx . container . use ( 'grantService' )
20
18
const { filter, sortOrder, ...pagination } = args
21
19
const grants = await grantService . getPage ( pagination , filter , sortOrder )
@@ -34,11 +32,9 @@ export const getGrants: QueryResolvers<ApolloContext>['grants'] = async (
34
32
}
35
33
}
36
34
37
- export const getGrantById : QueryResolvers < ApolloContext > [ 'grant' ] = async (
38
- _ ,
39
- args ,
40
- ctx
41
- ) : Promise < ResolversTypes [ 'Grant' ] > => {
35
+ export const getGrantById : NonNullable <
36
+ QueryResolvers < ApolloContext > [ 'grant' ]
37
+ > = async ( _ , args , ctx ) : Promise < ResolversTypes [ 'Grant' ] > => {
42
38
const grantService = await ctx . container . use ( 'grantService' )
43
39
const grant = await grantService . getByIdWithAccess ( args . id )
44
40
@@ -49,53 +45,54 @@ export const getGrantById: QueryResolvers<ApolloContext>['grant'] = async (
49
45
return grantToGraphql ( grant )
50
46
}
51
47
52
- export const revokeGrant : MutationResolvers < ApolloContext > [ 'revokeGrant' ] =
53
- async (
54
- _ ,
55
- args ,
56
- ctx
57
- ) : Promise < ResolversTypes [ 'RevokeGrantMutationResponse' ] > => {
58
- try {
59
- const { grantId } = args . input
60
- if ( ! grantId ) {
61
- return {
62
- code : '401' ,
63
- success : false ,
64
- message : 'Grant Id is not provided'
65
- }
66
- }
67
-
68
- const grantService = await ctx . container . use ( 'grantService' )
69
- const revoked = await grantService . revokeGrant ( grantId )
70
- if ( ! revoked ) {
71
- return {
72
- code : '404' ,
73
- success : false ,
74
- message : 'Revoke grant was not successful'
75
- }
76
- }
77
-
48
+ export const revokeGrant : NonNullable <
49
+ MutationResolvers < ApolloContext > [ 'revokeGrant' ]
50
+ > = async (
51
+ _ ,
52
+ args ,
53
+ ctx
54
+ ) : Promise < ResolversTypes [ 'RevokeGrantMutationResponse' ] > => {
55
+ try {
56
+ const { grantId } = args . input
57
+ if ( ! grantId ) {
78
58
return {
79
- code : '200 ' ,
80
- success : true ,
81
- message : 'Grant revoked '
59
+ code : '401 ' ,
60
+ success : false ,
61
+ message : 'Grant Id is not provided '
82
62
}
83
- } catch ( err ) {
84
- ctx . logger . error (
85
- {
86
- options : args . input . grantId ,
87
- err
88
- } ,
89
- 'error revoking grant'
90
- )
63
+ }
91
64
65
+ const grantService = await ctx . container . use ( 'grantService' )
66
+ const revoked = await grantService . revokeGrant ( grantId )
67
+ if ( ! revoked ) {
92
68
return {
93
- code : '500 ' ,
94
- message : 'Error trying to revoke grant' ,
95
- success : false
69
+ code : '404 ' ,
70
+ success : false ,
71
+ message : 'Revoke grant was not successful'
96
72
}
97
73
}
74
+
75
+ return {
76
+ code : '200' ,
77
+ success : true ,
78
+ message : 'Grant revoked'
79
+ }
80
+ } catch ( err ) {
81
+ ctx . logger . error (
82
+ {
83
+ options : args . input . grantId ,
84
+ err
85
+ } ,
86
+ 'error revoking grant'
87
+ )
88
+
89
+ return {
90
+ code : '500' ,
91
+ message : 'Error trying to revoke grant' ,
92
+ success : false
93
+ }
98
94
}
95
+ }
99
96
100
97
export const grantToGraphql = ( grant : Grant ) : SchemaGrant => ( {
101
98
id : grant . id ,
0 commit comments