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

36 lines
910 B
TypeScript
Raw Normal View History

2021-01-02 21:40:13 +03:00
import { Injectable } from '@nestjs/common';
2020-03-19 16:21:35 +03:00
import { Reflector } from '@nestjs/core';
import {
2021-01-02 21:40:13 +03:00
SCENE_METADATA,
UPDATE_LISTENER_METADATA,
UPDATE_METADATA,
} 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) {}
2021-01-02 21:40:13 +03:00
isUpdate(target: Function): boolean {
if (!target) {
return false;
}
2021-01-02 21:40:13 +03:00
return !!this.reflector.get(UPDATE_METADATA, target);
}
2021-01-02 21:40:13 +03:00
isScene(target: Function): boolean {
2020-03-19 17:20:13 +03:00
if (!target) {
return false;
}
2021-01-02 21:40:13 +03:00
return !!this.reflector.get(SCENE_METADATA, target);
2020-03-19 17:20:13 +03:00
}
2021-01-02 21:40:13 +03:00
getListenerMetadata(target: Function): ListenerMetadata | undefined {
return this.reflector.get(UPDATE_LISTENER_METADATA, target);
}
2021-01-02 21:40:13 +03:00
getSceneMetadata(target: Function): string | undefined {
return this.reflector.get(SCENE_METADATA, target);
}
2020-03-19 16:21:35 +03:00
}