6
6
ObjectType ,
7
7
Resolver ,
8
8
} from '@nestjs/graphql' ;
9
- import { LoggedInSession , type Session , UnauthorizedException } from '~/common' ;
10
9
import { MarkdownScalar } from '~/common/markdown.scalar' ;
11
- import { isAdmin } from '~/common/session ' ;
10
+ import { Privileges } from '../authorization ' ;
12
11
import { NotificationService } from '../notifications' ;
13
12
import { SystemNotification } from './system-notification.dto' ;
14
13
@@ -23,17 +22,16 @@ export class SystemNotificationCreationOutput {
23
22
24
23
@Resolver ( SystemNotification )
25
24
export class SystemNotificationResolver {
26
- constructor ( private readonly notifications : NotificationService ) { }
25
+ constructor (
26
+ private readonly notifications : NotificationService ,
27
+ private readonly privileges : Privileges ,
28
+ ) { }
27
29
28
30
@Mutation ( ( ) => SystemNotificationCreationOutput )
29
31
async createSystemNotification (
30
32
@Args ( { name : 'message' , type : ( ) => MarkdownScalar } ) message : string ,
31
- @LoggedInSession ( ) session : Session ,
32
33
) : Promise < SystemNotificationCreationOutput > {
33
- if ( ! isAdmin ( session ) ) {
34
- throw new UnauthorizedException ( ) ;
35
- }
36
-
34
+ this . privileges . for ( SystemNotification ) . verifyCan ( 'create' ) ;
37
35
return await this . notifications . create ( SystemNotification , null , {
38
36
message,
39
37
} ) ;
0 commit comments