From 5dec57ca55ea41ce3d635b881ee34b0fce784a9b Mon Sep 17 00:00:00 2001 From: Kalle Virtaneva Date: Mon, 16 Dec 2019 10:37:08 -0500 Subject: [PATCH] feat(repository): add interface for hasManyThrough repository The hasManyThrough repository interface defines the actions that can be performed on a many-to-many model relation. This PR is a continuation of https://github.com/strongloop/loopback-next/pull/2359 and implements a step from https://github.com/strongloop/loopback-next/pull/2359#issuecomment-559719080. --- .../has-many/has-many-through.repository.ts | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 packages/repository/src/relations/has-many/has-many-through.repository.ts diff --git a/packages/repository/src/relations/has-many/has-many-through.repository.ts b/packages/repository/src/relations/has-many/has-many-through.repository.ts new file mode 100644 index 000000000000..455fa2a6f3a2 --- /dev/null +++ b/packages/repository/src/relations/has-many/has-many-through.repository.ts @@ -0,0 +1,100 @@ +import {Count, DataObject, Entity, Filter, Options, Where} from '../..'; + +/** + * CRUD operations for a target repository of a HasManyThrough relation + */ +export interface HasManyThroughRepository< + Target extends Entity, + TargetID, + Through extends Entity +> { + /** + * Create a target model instance + * @param targetModelData - The target model data + * @param throughModelData - The through model data + * @param options - Options for the operation + * @param throughOptions - Options passed to create through + * @returns A promise which resolves to the newly created target model instance + */ + create( + targetModelData: DataObject, + throughModelData?: DataObject, + options?: Options, + throughOptions?: Options, + ): Promise; + /** + * Find target model instance(s) + * @param filter - A filter object for where, order, limit, etc. + * @param options - Options for the operation + * @returns A promise which resolves with the found target instance(s) + */ + find( + filter?: Filter, + options?: Options, + throughOptions?: Options, + ): Promise; + /** + * Delete multiple target model instances + * @param where - Instances within the where scope are deleted + * @param options + * @returns A promise which resolves the deleted target model instances + */ + delete( + where?: Where, + options?: Options, + throughOptions?: Options, + ): Promise; + /** + * Patch multiple target model instances + * @param dataObject - The fields and their new values to patch + * @param where - Instances within the where scope are patched + * @param options + * @returns A promise which resolves the patched target model instances + */ + patch( + dataObject: DataObject, + where?: Where, + options?: Options, + throughOptions?: Options, + ): Promise; + + /** + * Creates a new many-to-many association to an existing target model instance + * @param targetModel - The target model to link + * @param options + * @param throughOptions + * @returns A promise which resolves to the linked target model instance + */ + add( + targetModel: Target, + options?: Options, + throughOptions?: Options, + ): Promise; + + /** + * Removes an association to an existing target model instance + * @param targetModel - The target model to unlink + * @param options + * @param throughOptions + * @returns A promise which resolves to null + */ + remove( + targetModel: Target, + options?: Options, + throughOptions?: Options, + ): Promise; + + /** + * Checks if the given target model instance is associated with the source model. + * @param targetModel - The target model to check + * @param options + * @param throughOptions + * @returns A promise which resolves to true when the association exists + * and false otherwise. + */ + exists( + targetModel: Target, + options?: Options, + throughOptions?: Options, + ): Promise; +}