Skip to content

Commit

Permalink
fix: improve initialization of custom repository (#8782)
Browse files Browse the repository at this point in the history
* fix: improve initialization of custom repository

* fix: edit custom repository test
  • Loading branch information
parly committed Mar 23, 2022
1 parent 7cc1848 commit 52a641c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/repository/Repository.ts
Expand Up @@ -634,13 +634,13 @@ export class Repository<Entity extends ObjectLiteral> {
// ...this,
// ...custom
// };
const thisRepo: any = this.constructor
const thisRepo = this.constructor as new (...args: any[]) => typeof this
const { target, manager, queryRunner } = this
const cls = new (class extends thisRepo {
constructor() {
super(target, manager, queryRunner)
}
})()
const cls = new (class extends thisRepo {})(
target,
manager,
queryRunner,
)
Object.assign(cls, custom)
return cls as any
}
Expand Down
12 changes: 6 additions & 6 deletions src/repository/TreeRepository.ts
Expand Up @@ -413,13 +413,13 @@ export class TreeRepository<Entity> extends Repository<Entity> {
custom: CustomRepository &
ThisType<TreeRepository<Entity> & CustomRepository>,
): TreeRepository<Entity> & CustomRepository {
const thisRepo: any = this.constructor
const thisRepo = this.constructor as new (...args: any[]) => typeof this
const { target, manager, queryRunner } = this
const cls = new (class extends thisRepo {
constructor() {
super(target, manager, queryRunner)
}
})()
const cls = new (class extends thisRepo {})(
target,
manager,
queryRunner,
)
Object.assign(cls, custom)
return cls as any
}
Expand Down
4 changes: 3 additions & 1 deletion test/functional/custom-repository/custom-repository.test.ts
Expand Up @@ -43,7 +43,9 @@ describe("custom repository", () => {
await transactionalManager.withRepository(
CustomRepository,
)
await CustomRepository.save({ name: "Natures Prophet" })
await transactionalCustomRepository.save({
name: "Natures Prophet",
})
const user =
await transactionalCustomRepository.findOneByName(
"Natures Prophet",
Expand Down

0 comments on commit 52a641c

Please sign in to comment.