diff --git a/packages/repository/src/relations/has-many/has-many-through-repository.factory.ts b/packages/repository/src/relations/has-many/has-many-through-repository.factory.ts new file mode 100644 index 000000000000..477b1c3eb717 --- /dev/null +++ b/packages/repository/src/relations/has-many/has-many-through-repository.factory.ts @@ -0,0 +1,34 @@ +import {Entity, EntityCrudRepository, Getter, HasManyThroughDefinition} from "../.."; +import {DefaultHasManyThroughRepository, HasManyThroughRepository} from "./has-many-through.repository"; + +export type HasManyThroughRepositoryFactory< + TargetEntity extends Entity, + TargetID, + ThroughEntity extends Entity, + ThroughID, +> = (fkValue: ThroughID) => HasManyThroughRepository; + +export function createHasManyThroughRepositoryFactory< + TargetEntity extends Entity, + TargetID, + ThroughEntity extends Entity, + ThroughID, +>( + relationMetadata: HasManyThroughDefinition, + targetRepositoryGetter: Getter>, + throughRepositoryGetter: Getter>, +): HasManyThroughRepositoryFactory { + return (fkValue?: ThroughID) => { + return new DefaultHasManyThroughRepository< + TargetEntity, + TargetID, + EntityCrudRepository, + ThroughEntity, + ThroughID, + EntityCrudRepository + >( + targetRepositoryGetter, + throughRepositoryGetter, + ); + } +} diff --git a/packages/repository/src/relations/has-many/index.ts b/packages/repository/src/relations/has-many/index.ts index 36521896f913..44e3d81547f8 100644 --- a/packages/repository/src/relations/has-many/index.ts +++ b/packages/repository/src/relations/has-many/index.ts @@ -7,4 +7,5 @@ export * from './has-many.decorator'; export * from './has-many.repository'; export * from './has-many-repository.factory'; export * from './has-many.inclusion-resolver'; +export * from './has-many-through-repository.factory'; export * from './has-many-through.repository';