From 1acb8e7d203f2185d35cde7c5e16d5c5fbed8862 Mon Sep 17 00:00:00 2001 From: derdeka Date: Wed, 15 Jan 2020 15:33:15 +0100 Subject: [PATCH] feat(repository): hasManyThrough - add HasManyThroughRepositoryFactory --- .../has-many-through-repository.factory.ts | 34 +++++++++++++++++++ .../src/relations/has-many/index.ts | 1 + 2 files changed, 35 insertions(+) create mode 100644 packages/repository/src/relations/has-many/has-many-through-repository.factory.ts 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';