mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 23:14:39 +03:00
fix(): update decorator detection
This commit is contained in:
parent
0dc981dc95
commit
66309b9415
@ -3,7 +3,7 @@ import {
|
||||
UPDATE_LISTENER_OPTIONS_METADATA,
|
||||
UPDATE_LISTENER_TYPE_METADATA,
|
||||
} from '../../telegraf.constants';
|
||||
import { ListenerType } from '../../enums/listener-type.enum';
|
||||
import { ListenerType } from '../../enums';
|
||||
import { TelegrafHearsTriggers } from '../../telegraf.types';
|
||||
|
||||
export interface HearsOptions {
|
||||
|
@ -24,33 +24,27 @@ import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
|
||||
@Injectable()
|
||||
export class TelegrafExplorer implements OnModuleInit {
|
||||
constructor(
|
||||
private readonly moduleRef: ModuleRef,
|
||||
private readonly telegraf: TelegrafProvider,
|
||||
private readonly discoveryService: DiscoveryService,
|
||||
private readonly metadataAccessor: TelegrafMetadataAccessor,
|
||||
private readonly metadataScanner: MetadataScanner,
|
||||
) {}
|
||||
|
||||
private telegraf: TelegrafProvider;
|
||||
|
||||
onModuleInit(): void {
|
||||
this.telegraf = this.moduleRef.get<TelegrafProvider>(TelegrafProvider, {
|
||||
strict: false,
|
||||
});
|
||||
this.explore();
|
||||
}
|
||||
|
||||
explore(): void {
|
||||
const updateInstanceWrappers = this.filterUpdateClass();
|
||||
const updateClasses = this.filterUpdateClass();
|
||||
|
||||
updateInstanceWrappers.forEach((wrapper) => {
|
||||
updateClasses.forEach((wrapper) => {
|
||||
const { instance } = wrapper;
|
||||
|
||||
const prototype = Object.getPrototypeOf(instance);
|
||||
this.metadataScanner.scanFromPrototype(
|
||||
instance,
|
||||
prototype,
|
||||
(methodKey: string) =>
|
||||
this.registerIfUpdateListener(instance, methodKey),
|
||||
(methodKey: string) => this.registerIfListener(instance, methodKey),
|
||||
);
|
||||
});
|
||||
}
|
||||
@ -59,10 +53,12 @@ export class TelegrafExplorer implements OnModuleInit {
|
||||
return this.discoveryService
|
||||
.getProviders()
|
||||
.filter((wrapper) => wrapper.instance)
|
||||
.filter((wrapper) => this.metadataAccessor.isUpdate(wrapper.instance));
|
||||
.filter((wrapper) =>
|
||||
this.metadataAccessor.isUpdate(wrapper.instance.constructor),
|
||||
);
|
||||
}
|
||||
|
||||
private registerIfUpdateListener(
|
||||
private registerIfListener(
|
||||
instance: Record<string, Function>,
|
||||
methodKey: string,
|
||||
): void {
|
||||
|
@ -2,8 +2,8 @@ import { Injectable } from '@nestjs/common';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import {
|
||||
UPDATE_LISTENER_TYPE_METADATA,
|
||||
TELEGRAF_MODULE_OPTIONS,
|
||||
UPDATE_METADATA,
|
||||
UPDATE_LISTENER_OPTIONS_METADATA,
|
||||
} from './telegraf.constants';
|
||||
import { ListenerType } from './enums';
|
||||
|
||||
@ -22,7 +22,10 @@ export class TelegrafMetadataAccessor {
|
||||
);
|
||||
}
|
||||
|
||||
getListenerOptions<T>(target: Function): unknown | undefined {
|
||||
return this.reflector.get<unknown>(TELEGRAF_MODULE_OPTIONS, target);
|
||||
getListenerOptions(target: Function): unknown | undefined {
|
||||
return this.reflector.get<unknown>(
|
||||
UPDATE_LISTENER_OPTIONS_METADATA,
|
||||
target,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user