feat: TelegrafUse decorator added

This commit is contained in:
Aleksandr Bukhalo
2020-03-19 16:34:44 +03:00
parent 9fedcb964f
commit 6fddfd26f0
5 changed files with 31 additions and 1 deletions

View File

@@ -39,7 +39,9 @@ export class TelegrafExplorer implements OnModuleInit {
instance,
Object.getPrototypeOf(instance),
(key: string) => {
if (this.metadataAccessor.isTelegrafStart(instance[key])) {
if (this.metadataAccessor.isTelegrafUse(instance[key])) {
this.handleTelegrafUse(instance, key, telegraf);
} else if (this.metadataAccessor.isTelegrafStart(instance[key])) {
this.handleTelegrafStart(instance, key, telegraf);
} else if (this.metadataAccessor.isTelegrafOn(instance[key])) {
const metadata = this.metadataAccessor.getTelegrafOnMetadata(
@@ -57,6 +59,14 @@ export class TelegrafExplorer implements OnModuleInit {
});
}
handleTelegrafUse(
instance: object,
key: string,
telegraf: Telegraf<ContextMessageUpdate>,
) {
telegraf.use(instance[key].bind(instance));
}
handleTelegrafOn(
instance: object,
key: string,