Skip to content

Commit 2b9cd9b

Browse files
committed
Add helper to get the attachedType resource
Since it's likely that listeners will need to base logic off this, it makes sense to provide this for them and only do it once.
1 parent 21b60ba commit 2b9cd9b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
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';
23
import { PollVoter } from '~/common';
4+
import { ResourceResolver, ResourcesHost } from '~/core';
35
import { AnyMedia, MediaUserMetadata } from '../media.dto';
46

57
/**
@@ -8,9 +10,20 @@ import { AnyMedia, MediaUserMetadata } from '../media.dto';
810
*/
911
@Injectable({ scope: Scope.TRANSIENT })
1012
export class CanUpdateMediaUserMetadataEvent {
13+
@Inject() private readonly resourceHost: ResourcesHost;
14+
@Inject() private readonly resourceResolver: ResourceResolver;
15+
1116
constructor(
1217
@Optional() readonly media: AnyMedia,
1318
@Optional() readonly input: MediaUserMetadata,
1419
@Optional() readonly allowUpdate: PollVoter<boolean>,
1520
) {}
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+
}
1629
}

0 commit comments

Comments
 (0)