alphamikle / nest_transact

Simplest transactions support for Nestjs with Typeorm
MIT License
116 stars 20 forks source link

Cannot resolve ids of forwardRefs #5

Closed sarathas closed 2 years ago

sarathas commented 3 years ago

When a service has a forwardRef in its constructor, the id is undefined. Attempting to create a transactional service with a forwardRef results in an error when the id is scanned if it is a repository:

TypeError: Cannot read property 'includes' of undefined
    at SomeService.getArgument (/path/to/application/node_modules/nest-transact/lib/with-transaction.ts:47:32)
//... rest of the stack trace

Example for a service with forwardRefs:

@Injectable()
export class SomeService extends TransactionFor<SomeService> {
  constructor(
    @InjectRepository(SomeRepository)
    private readonly someRepository: SomeRepository,
    @Inject(forwardRef(() => SomeOtherClass))
    private someOtherClass: SomeOtherClass,
    moduleRef: ModuleRef,
  ) {
    super(moduleRef);
  }
}

The object in this case is a ForwardReference (provided by @nestjs/common), so one could get the forwardRef function of that object, execute it, and get the id by its name, for example.

sarathas commented 3 years ago

Btw excluding the forwardRef does not work either as of right now, since the id is undefined.

alphamikle commented 3 years ago

Hello, @sarathas ! It needs to be investigated

alphamikle commented 3 years ago

@sarathas, Hi! Please, check v.1.1.4, which has fixes for forwardRef from the community developer. I hope this version fix your problem. And... PRs are welcome!

alphamikle commented 3 years ago

@sarathas is v1.1.4 or the newest v1.1.5 fix this problem?

sarathas commented 3 years ago

It does, thank you! I hope I will find time to file a PR myself, should there be any further problems.

pvhuy84 commented 3 years ago

No, it not working

alphamikle commented 2 years ago

@sarathas, @pvhuy84, hello!

Feel free to send PR with the fix of this issue, if it is annoying for you. Unfortunately for now I don't have much time to fix specific errors.