feat(wip): add updates decorators

This commit is contained in:
unknown
2020-12-23 21:48:07 +03:00
parent b1a6fc3319
commit b394f5274b
5 changed files with 71 additions and 105 deletions

View File

@@ -0,0 +1,25 @@
import { applyDecorators, SetMetadata } from '@nestjs/common';
import {
TELEGRAF_LISTENER_OPTIONS,
TELEGRAF_LISTENER_TYPE,
} from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum';
import { TelegrafUpdateType } from '../../telegraf.types';
export interface OnOptions {
updateTypes: TelegrafUpdateType;
}
/**
* Registers middleware for provided update type.
*
* @see https://telegraf.js.org/#/?id=on
*/
export const On = (updateTypes: TelegrafUpdateType): MethodDecorator => {
return applyDecorators(
SetMetadata(TELEGRAF_LISTENER_TYPE, ListenerType.On),
SetMetadata(TELEGRAF_LISTENER_OPTIONS, {
updateTypes,
} as OnOptions),
);
};

View File

@@ -0,0 +1,12 @@
import { SetMetadata } from '@nestjs/common';
import { TELEGRAF_LISTENER_TYPE } from '../../telegraf.constants';
import { ListenerType } from '../../enums/listener-type.enum';
/**
* Registers a middleware.
*
* @see https://telegraf.js.org/#/?id=use
*/
export const Use = (): MethodDecorator => {
return SetMetadata(TELEGRAF_LISTENER_TYPE, ListenerType.Use);
};