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

41 lines
1.1 KiB
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,
LISTENERS_METADATA,
2020-12-26 16:11:09 +03:00
UPDATE_METADATA,
WIZARD_STEP_METADATA,
2021-01-02 21:40:13 +03:00
} from '../telegraf.constants';
import {
ListenerMetadata,
SceneMetadata,
WizardStepMetadata,
} 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 {
if (!target) return false;
return !!this.reflector.get(UPDATE_METADATA, target);
}
isScene(target: Function): boolean {
if (!target) return false;
return !!this.reflector.get(SCENE_METADATA, target);
}
getListenerMetadata(target: Function): ListenerMetadata[] | undefined {
return this.reflector.get(LISTENERS_METADATA, target);
}
getSceneMetadata(target: Function): SceneMetadata | undefined {
return this.reflector.get(SCENE_METADATA, target);
}
getWizardStepMetadata(target: Function): WizardStepMetadata | undefined {
return this.reflector.get(WIZARD_STEP_METADATA, target);
}
2020-03-19 16:21:35 +03:00
}