mirror of
https://github.com/Maks1mS/nestjs-telegraf.git
synced 2024-12-24 23:14:39 +03:00
feat(param-decorators): add new paramtypes & make possible to get property from object
This commit is contained in:
parent
dc22f9f191
commit
4ca6e18d12
@ -1,3 +1,4 @@
|
|||||||
export * from './context.decorator';
|
export * from './context.decorator';
|
||||||
export * from './next.decorator';
|
export * from './next.decorator';
|
||||||
export * from './message-text.decorator';
|
export * from './message.decorator';
|
||||||
|
export * from './sender.decorator';
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
import { PipeTransform, Type } from '@nestjs/common';
|
|
||||||
import { createTelegrafPipesParamDecorator } from '../../utils/param-decorator.util';
|
|
||||||
import { TelegrafParamtype } from '../../enums/telegraf-paramtype.enum';
|
|
||||||
|
|
||||||
export function MessageText(...pipes: (Type<PipeTransform> | PipeTransform)[]) {
|
|
||||||
return createTelegrafPipesParamDecorator(TelegrafParamtype.MESSAGE_TEXT)(
|
|
||||||
undefined,
|
|
||||||
...pipes,
|
|
||||||
);
|
|
||||||
}
|
|
21
lib/decorators/params/message.decorator.ts
Normal file
21
lib/decorators/params/message.decorator.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { PipeTransform, Type } from '@nestjs/common';
|
||||||
|
import { createTelegrafPipesParamDecorator } from '../../utils/param-decorator.util';
|
||||||
|
import { TelegrafParamtype } from '../../enums/telegraf-paramtype.enum';
|
||||||
|
|
||||||
|
export function Message(): ParameterDecorator;
|
||||||
|
export function Message(
|
||||||
|
...pipes: (Type<PipeTransform> | PipeTransform)[]
|
||||||
|
): ParameterDecorator;
|
||||||
|
export function Message(
|
||||||
|
property: string,
|
||||||
|
...pipes: (Type<PipeTransform> | PipeTransform)[]
|
||||||
|
): ParameterDecorator;
|
||||||
|
export function Message(
|
||||||
|
property?: string | (Type<PipeTransform> | PipeTransform),
|
||||||
|
...pipes: (Type<PipeTransform> | PipeTransform)[]
|
||||||
|
) {
|
||||||
|
return createTelegrafPipesParamDecorator(TelegrafParamtype.MESSAGE)(
|
||||||
|
property,
|
||||||
|
...pipes,
|
||||||
|
);
|
||||||
|
}
|
21
lib/decorators/params/sender.decorator.ts
Normal file
21
lib/decorators/params/sender.decorator.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { PipeTransform, Type } from '@nestjs/common';
|
||||||
|
import { createTelegrafPipesParamDecorator } from '../../utils/param-decorator.util';
|
||||||
|
import { TelegrafParamtype } from '../../enums/telegraf-paramtype.enum';
|
||||||
|
|
||||||
|
export function Sender(): ParameterDecorator;
|
||||||
|
export function Sender(
|
||||||
|
...pipes: (Type<PipeTransform> | PipeTransform)[]
|
||||||
|
): ParameterDecorator;
|
||||||
|
export function Sender(
|
||||||
|
property: string,
|
||||||
|
...pipes: (Type<PipeTransform> | PipeTransform)[]
|
||||||
|
): ParameterDecorator;
|
||||||
|
export function Sender(
|
||||||
|
property?: string | (Type<PipeTransform> | PipeTransform),
|
||||||
|
...pipes: (Type<PipeTransform> | PipeTransform)[]
|
||||||
|
) {
|
||||||
|
return createTelegrafPipesParamDecorator(TelegrafParamtype.SENDER)(
|
||||||
|
property,
|
||||||
|
...pipes,
|
||||||
|
);
|
||||||
|
}
|
@ -3,6 +3,5 @@ export enum TelegrafParamtype {
|
|||||||
NEXT,
|
NEXT,
|
||||||
SENDER,
|
SENDER,
|
||||||
MESSAGE,
|
MESSAGE,
|
||||||
MESSAGE_TEXT,
|
// TODO-Possible-Feature: Add more paramtypes
|
||||||
// TODO: Add more
|
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,9 @@ export class TelegrafParamsFactory implements ParamsFactory {
|
|||||||
case TelegrafParamtype.NEXT:
|
case TelegrafParamtype.NEXT:
|
||||||
return next;
|
return next;
|
||||||
case TelegrafParamtype.SENDER:
|
case TelegrafParamtype.SENDER:
|
||||||
return ctx.from;
|
return ctx.from ? ctx.from[data as string] : ctx.from;
|
||||||
case TelegrafParamtype.MESSAGE:
|
case TelegrafParamtype.MESSAGE:
|
||||||
return ctx.message;
|
return ctx.message ? ctx.message[data as string] : ctx.message;
|
||||||
case TelegrafParamtype.MESSAGE_TEXT:
|
|
||||||
return ctx.message.text;
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user