mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2025-09-23 09:49:06 +03:00
feat(wip): add updates decorators
This commit is contained in:
25
lib/decorators/core/on.decorator.ts
Normal file
25
lib/decorators/core/on.decorator.ts
Normal 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),
|
||||
);
|
||||
};
|
12
lib/decorators/core/use.decorator.ts
Normal file
12
lib/decorators/core/use.decorator.ts
Normal 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);
|
||||
};
|
Reference in New Issue
Block a user