UNPKG

1.97 kBJavaScriptView Raw
1"use strict";
2// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
3// Node module: @loopback/repository
4// This file is licensed under the MIT License.
5// License text available at https://opensource.org/licenses/MIT
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.DefaultHasManyRepository = void 0;
8const repositories_1 = require("../../repositories");
9class DefaultHasManyRepository {
10 /**
11 * Constructor of DefaultHasManyEntityCrudRepository
12 * @param getTargetRepository - the getter of the related target model repository instance
13 * @param constraint - the key value pair representing foreign key name to constrain
14 * the target repository instance
15 */
16 constructor(getTargetRepository, constraint) {
17 this.getTargetRepository = getTargetRepository;
18 this.constraint = constraint;
19 }
20 async create(targetModelData, options) {
21 const targetRepository = await this.getTargetRepository();
22 return targetRepository.create((0, repositories_1.constrainDataObject)(targetModelData, this.constraint), options);
23 }
24 async find(filter, options) {
25 const targetRepository = await this.getTargetRepository();
26 return targetRepository.find((0, repositories_1.constrainFilter)(filter, this.constraint), options);
27 }
28 async delete(where, options) {
29 const targetRepository = await this.getTargetRepository();
30 return targetRepository.deleteAll((0, repositories_1.constrainWhere)(where, this.constraint), options);
31 }
32 async patch(dataObject, where, options) {
33 const targetRepository = await this.getTargetRepository();
34 return targetRepository.updateAll((0, repositories_1.constrainDataObject)(dataObject, this.constraint), (0, repositories_1.constrainWhere)(where, this.constraint), options);
35 }
36}
37exports.DefaultHasManyRepository = DefaultHasManyRepository;
38//# sourceMappingURL=has-many.repository.js.map
\No newline at end of file