Skip to content

Commit

Permalink
feat(repository): hasManyThrough - add HasManyThroughRepositoryFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
derdeka committed Jan 21, 2020
1 parent 42078be commit 461160b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<TargetEntity, TargetID, ThroughEntity>;

export function createHasManyThroughRepositoryFactory<
TargetEntity extends Entity,
TargetID,
ThroughEntity extends Entity,
ThroughID,
>(
relationMetadata: HasManyThroughDefinition,
targetRepositoryGetter: Getter<EntityCrudRepository<TargetEntity, TargetID>>,
throughRepositoryGetter: Getter<EntityCrudRepository<ThroughEntity, ThroughID>>,
): HasManyThroughRepositoryFactory<TargetEntity, TargetID, ThroughEntity, ThroughID> {
return (fkValue?: ThroughID) => {
return new DefaultHasManyThroughRepository<
TargetEntity,
TargetID,
EntityCrudRepository<TargetEntity, TargetID>,
ThroughEntity,
ThroughID,
EntityCrudRepository<ThroughEntity, ThroughID>
>(
targetRepositoryGetter,
throughRepositoryGetter,
);
}
}
1 change: 1 addition & 0 deletions packages/repository/src/relations/has-many/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 461160b

Please sign in to comment.