NestJS-向管道添加其他元数据

NestJS-向管道添加其他元数据,nestjs,Nestjs,有没有办法向NestJS管道添加额外的元数据 元数据属性具有以下值: export interface ArgumentMetadata { type: 'body' | 'query' | 'param' | 'custom'; metatype?: Type<any>; data?: string; } 导出接口元数据{ 键入:“body”|“query”|“param”|“custom”; 元类型?:类型我能够通过自定义参数装饰器和自定义管道添加额外的元数据 im

有没有办法向NestJS管道添加额外的元数据

元数据属性具有以下值:

export interface ArgumentMetadata {
  type: 'body' | 'query' | 'param' | 'custom';
  metatype?: Type<any>;
  data?: string;
}
导出接口元数据{
键入:“body”|“query”|“param”|“custom”;

元类型?:类型

我能够通过自定义参数装饰器和自定义管道添加额外的元数据

import { createParamDecorator} from '@nestjs/common'

export const ExtractIdFromBody = createParamDecorator(
  (
    {
      property,
      entityLookupProperty = 'id'
    }: {
      property: string
      entityLookupProperty?: string
    },
    req
  ) => {
    const value = get(req.body, property)
    return {
      value,
      entityLookupProperty // the extra property
    }
  }
)
然后我用了一个装饰师,像这样:

@Post()
@UsePipes(new ValidationPipe({ transform: true }))
async doThing(
    @ExtractIdFromBody({ property: 'userId', entityLookupProperty: 'someProperty'  }, GetEntityOr404Pipe) entity: Entity,
  ): Promise<Entity[]> {
    return await this.Service.doThing(entity)
  }
@Post()
@UsePipes(新的ValidationPipe({transform:true}))
异步点处理(
@ExtractIdFromBody({property:'userId',entityLookupProperty:'someProperty'},GetEntityOr404Pipe)实体:实体,
):承诺{
返回等待此.Service.doThing(实体)
}