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

37 lines
936 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 {
SCENE_METADATA,
2021-01-05 12:37:04 +03:00
LISTENER_METADATA,
2020-12-26 16:11:09 +03:00
UPDATE_METADATA,
2021-01-02 21:40:13 +03:00
} from '../telegraf.constants';
import { ListenerMetadata } from '../interfaces';
2020-03-19 16:21:35 +03:00
@Injectable()
2021-01-02 01:27:01 +03:00
export class MetadataAccessorService {
2020-03-19 16:21:35 +03:00
constructor(private readonly reflector: Reflector) {}
isUpdate(target: Function): boolean {
2021-01-05 00:32:31 +03:00
// TODO: We really need this check?
if (!target) {
return false;
}
return !!this.reflector.get(UPDATE_METADATA, target);
}
isScene(target: Function): boolean {
2020-03-19 17:20:13 +03:00
if (!target) {
return false;
}
return !!this.reflector.get(SCENE_METADATA, target);
}
getListenerMetadata(target: Function): ListenerMetadata | undefined {
2021-01-05 12:37:04 +03:00
return this.reflector.get(LISTENER_METADATA, target);
}
getSceneMetadata(target: Function): string | undefined {
return this.reflector.get(SCENE_METADATA, target);
}
2020-03-19 16:21:35 +03:00
}