nestjs-telegraf/lib/telegraf.metadata-accessor.ts

29 lines
795 B
TypeScript
Raw Normal View History

import { Injectable } from '@nestjs/common';
2020-03-19 16:21:35 +03:00
import { Reflector } from '@nestjs/core';
import {
2020-12-26 16:11:09 +03:00
UPDATE_LISTENER_TYPE_METADATA,
TELEGRAF_MODULE_OPTIONS,
2020-12-26 16:11:09 +03:00
UPDATE_METADATA,
} from './telegraf.constants';
import { ListenerType } from './enums';
2020-03-19 16:21:35 +03:00
@Injectable()
export class TelegrafMetadataAccessor {
constructor(private readonly reflector: Reflector) {}
isUpdate(target: Function): boolean {
2020-12-26 16:11:09 +03:00
return !!this.reflector.get<true | undefined>(UPDATE_METADATA, target);
}
getListenerType(target: Function): ListenerType | undefined {
2020-12-26 16:11:09 +03:00
return this.reflector.get<ListenerType>(
UPDATE_LISTENER_TYPE_METADATA,
target,
);
}
getListenerOptions<T>(target: Function): unknown | undefined {
return this.reflector.get<unknown>(TELEGRAF_MODULE_OPTIONS, target);
}
2020-03-19 16:21:35 +03:00
}