Skip to content

Commit 063648b

Browse files
KalleVdhmlau
authored andcommitted
refactor: extend repository methods directly
Signed-off-by: KalleV <kvirtaneva@gmail.com>
1 parent 5b7e6cb commit 063648b

2 files changed

Lines changed: 24 additions & 15 deletions

File tree

extensions/sequelize/src/sequelize/sequelize.repository.base.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ import {isTruelyObject} from './utils';
6868
const debug = debugFactory('loopback:sequelize:repository');
6969
const debugModelBuilder = debugFactory('loopback:sequelize:modelbuilder');
7070

71+
interface InclusionWithRequired extends Inclusion {
72+
/**
73+
* Setting this option to true will result in an inner join query that
74+
* explicitly requires the specified condition for the child model.
75+
*
76+
* @see https://loopback.io/pages/en/lb4/readmes/loopback-next/extensions/sequelize/#inner-join
77+
*/
78+
required?: boolean;
79+
}
80+
81+
type InclusionFilterWithRequired = string | InclusionWithRequired;
82+
83+
interface FilterWithRequired<T extends object> extends Filter<T> {
84+
include?: InclusionFilterWithRequired[];
85+
}
86+
87+
type FilterWithRequiredExcludingWhere<T extends object> = Omit<
88+
FilterExcludingWhere<T>,
89+
'where'
90+
>;
91+
7192
/**
7293
* Sequelize implementation of CRUD repository to be used with default loopback entities
7394
* and SequelizeDataSource for SQL Databases
@@ -231,7 +252,7 @@ export class SequelizeCrudRepository<
231252
}
232253

233254
async find(
234-
filter?: Filter<T>,
255+
filter?: FilterWithRequired<T>,
235256
options?: AnyObject,
236257
): Promise<(T & Relations)[]> {
237258
const data = await this.sequelizeModel.findAll({
@@ -252,7 +273,7 @@ export class SequelizeCrudRepository<
252273
}
253274

254275
async findOne(
255-
filter?: Filter<T>,
276+
filter?: FilterWithRequired<T>,
256277
options?: AnyObject,
257278
): Promise<(T & Relations) | null> {
258279
const data = await this.sequelizeModel.findOne({
@@ -279,7 +300,7 @@ export class SequelizeCrudRepository<
279300

280301
async findById(
281302
id: ID,
282-
filter?: FilterExcludingWhere<T>,
303+
filter?: FilterWithRequiredExcludingWhere<T>,
283304
options?: AnyObject,
284305
): Promise<T & Relations> {
285306
const data = await this.sequelizeModel.findByPk(

extensions/sequelize/src/types.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6-
declare module '@loopback/repository' {
7-
interface Inclusion {
8-
/**
9-
* Setting this option to true will result in an inner join query that
10-
* explicitly requires the specified condition for the child model.
11-
*
12-
* @see https://loopback.io/pages/en/lb4/readmes/loopback-next/extensions/sequelize/#inner-join
13-
*/
14-
required?: boolean;
15-
}
16-
}
17-
186
/**
197
* Interface defining the component's options object
208
*/

0 commit comments

Comments
 (0)