1
- import { Injectable , Optional , Scope } from '@nestjs/common' ;
1
+ import { Inject , Injectable , Optional , Scope } from '@nestjs/common' ;
2
+ import { CachedByArg as Once } from '@seedcompany/common' ;
2
3
import { PollVoter } from '~/common' ;
4
+ import { ResourceResolver , ResourcesHost } from '~/core' ;
3
5
import { AnyMedia , MediaUserMetadata } from '../media.dto' ;
4
6
5
7
/**
@@ -8,9 +10,20 @@ import { AnyMedia, MediaUserMetadata } from '../media.dto';
8
10
*/
9
11
@Injectable ( { scope : Scope . TRANSIENT } )
10
12
export class CanUpdateMediaUserMetadataEvent {
13
+ @Inject ( ) private readonly resourceHost : ResourcesHost ;
14
+ @Inject ( ) private readonly resourceResolver : ResourceResolver ;
15
+
11
16
constructor (
12
17
@Optional ( ) readonly media : AnyMedia ,
13
18
@Optional ( ) readonly input : MediaUserMetadata ,
14
19
@Optional ( ) readonly allowUpdate : PollVoter < boolean > ,
15
20
) { }
21
+
22
+ @Once ( ) async getAttachedResource ( ) {
23
+ const attachedResName = this . resourceResolver . resolveTypeByBaseNode (
24
+ this . media . attachedTo [ 0 ] ,
25
+ ) ;
26
+ const attachedResource = await this . resourceHost . getByName ( attachedResName ) ;
27
+ return attachedResource ;
28
+ }
16
29
}
0 commit comments