import { PipeTransform, Type } from '@nestjs/common'; import { assignMetadata } from '@nestjs/common/decorators/http/route-params.decorator'; import 'reflect-metadata'; import { PARAM_ARGS_METADATA } from '../constants'; import { RpcParamtype } from '../enums/rpc-paramtype.enum'; export function createRpcParamDecorator( paramtype: RpcParamtype, ): (...pipes: (Type | PipeTransform)[]) => ParameterDecorator { return (...pipes: (Type | PipeTransform)[]) => ( target, key, index, ) => { const args = Reflect.getMetadata(PARAM_ARGS_METADATA, target.constructor, key) || {}; Reflect.defineMetadata( PARAM_ARGS_METADATA, assignMetadata(args, paramtype, index, undefined, ...pipes), target.constructor, key, ); }; } export const createPipesRpcParamDecorator = (paramtype: RpcParamtype) => ( ...pipes: (Type | PipeTransform)[] ): ParameterDecorator => (target, key, index) => { const args = Reflect.getMetadata(PARAM_ARGS_METADATA, target.constructor, key) || {}; Reflect.defineMetadata( PARAM_ARGS_METADATA, assignMetadata(args, paramtype, index, undefined, ...pipes), target.constructor, key, ); };