Skip to content

Commit ca29c0f

Browse files
authored
feat: modify repository.extend method for chaining repositories (#10256)
* modify repository.extend method. so chainning call this method is possible * npm run format * add @ts-ignore at a line * Object.assign is no more needed * change code to remove @ts-ignore
1 parent fbd45db commit ca29c0f

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/repository/Repository.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -675,20 +675,25 @@ export class Repository<Entity extends ObjectLiteral> {
675675
* Extends repository with provided functions.
676676
*/
677677
extend<CustomRepository>(
678-
custom: CustomRepository & ThisType<this & CustomRepository>,
678+
customs: CustomRepository & ThisType<this & CustomRepository>,
679679
): this & CustomRepository {
680680
// return {
681681
// ...this,
682682
// ...custom
683683
// };
684-
const thisRepo = this.constructor as new (...args: any[]) => typeof this
684+
const thisRepo: any = this.constructor
685685
const { target, manager, queryRunner } = this
686-
const cls = new (class extends thisRepo {})(
687-
target,
688-
manager,
689-
queryRunner,
690-
)
691-
Object.assign(cls, custom)
692-
return cls as any
686+
const ChildClass = class extends thisRepo {
687+
constructor(
688+
target: EntityTarget<Entity>,
689+
manager: EntityManager,
690+
queryRunner?: QueryRunner,
691+
) {
692+
super(target, manager, queryRunner)
693+
}
694+
}
695+
for (const custom in customs)
696+
ChildClass.prototype[custom] = customs[custom]
697+
return new ChildClass(target, manager, queryRunner) as any
693698
}
694699
}

0 commit comments

Comments
 (0)