nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.09k stars 539 forks source link

reflect-metadata throws a TypeError when I use Crud decorator in conjunction with Client decorator #616

Open xitongzou opened 4 years ago

xitongzou commented 4 years ago

Hi, I am using the @Crud and @CrudAuth decorators in my code

@Crud({
  model: {
    type: User,
  },
  routes: {
    only: ['getOneBase'],
  },
  params: {
    id: {
      primary: true,
      disabled: true
    }
  },
  query: {
    join: {
      foo: {
        eager: true,
        required: false
      },
      bar: {
        eager: true,
        required: false
      }
    }
  }
})
@CrudAuth({
  property: 'user',
  filter: (user: User) => ({
    id: user.id,
  }),
})

and I am using it in conjunction with the @Client decorator from @nestjs/microservices

@Client(getClientConfig('grpc.auth.config'))
  private client: ClientGrpc
  private fooService: FooService

 onModuleInit() {
    try {
      this.fooService = this.client.getService<FooService>('FooService')
    } catch (e) {
      this.logger.error(`GRPC client can not resolve service: ${e}`)
    }
  }

and overriding the getOneBase route

@Override('getOneBase')
  @ApiOperation({ operationId: 'getOne' })
  async getOne(@ParsedRequest() req: CrudRequest) {
   ...
  }

and it doesn't seem to play together well, I get this error

/node_modules/reflect-metadata/Reflect.js:354 throw new TypeError();

TypeError
 at Object.getMetadata (/node_modules/reflect-metadata/Reflect.js:354:23)
at Function.get (/node_modules/@nestjsx/crud/lib/crud/reflection.helper.js:18:23)
at Function.getOverrideRoute (/node_modules/@nestjsx/crud/lib/crud/reflection.helper.js:81:18)
at util_1.getOwnPropNames.forEach (/node_modules/@nestjsx/crud/lib/crud/crud-routes.factory.js:252:52)
at Array.forEach (<anonymous>)
 at CrudRoutesFactory.overrideRoutes (/node_modules/@nestjsx/crud/lib/crud/crud-routes.factory.js:251:50)
at CrudRoutesFactory.create (/node_modules/@nestjsx/crud/lib/crud/crud-routes.factory.js:49:14)
at new CrudRoutesFactory (/node_modules/@nestjsx/crud/lib/crud/crud-routes.factory.js:19:14)
at Function.create (/node_modules/@nestjsx/crud/lib/crud/crud-routes.factory.js:22:16)
at /node_modules/@nestjsx/crud/lib/decorators/crud.decorator.js:5:44

I can't seem to figure out what might be causing this TypeError from Reflect-metadata but it seems to have something to do with a conflict with using the @Crud / @override decorators? Any ideas? Thanks