alphamikle / nest_transact

Simplest transactions support for Nestjs with Typeorm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Custom repository is not generated

sarathas opened this issue · comments

Hi,
I just had a case where I injected a custom repository into a service. There also is another injected class which also uses this repository, like this:

//repository.ts
@EntityRepository(MyEntity) 
export class MyRepository extends Repository<MyEntity> {
//...custom methods
}

//service.ts
export class MyService extends TransactionFor<MyService> {
  constructor(
    private myRepository: MyRepository,
    private myOtherClass: MyOtherClass,
    moduleRef: ModuleRef
  ) {
    super(moduleRef);
  }

  //...methods using myRepository      
}

//my-other-class.ts
@Injectable()
export class MyOtherClass {
  constructor(
    private myRepository: MyRepository
  )
}

When nest-transact 1.1.3 creates new repositories, it actually sees that there is a custom repository, but does not generate a new repository with the custom methods:

//line 64
argument = manager.getRepository(entity);

If this line is changed to

argument = isCustomRepository ? manager.getCustomRepository(param as any) : manager.getRepository(entity);

then it seems to actually generate a new repository with the custom method.

@sarathas, Hello! If you can send a pull request to fix this problem - this will be cool! I accept PR if they do work and haven't new bugs. To check this - you can run an example project - it is like a test field. And there are some custom repositories too, which works normally, as I know. Best regards!

@sarathas please, check v.1.1.5, which contains fixes for custom repositories from the community developer, if all is ok - I will close this issue

Works, thanks a lot!