1
- import { MixinTarget } from "@loopback/core" ;
1
+ import { MixinTarget , Context } from "@loopback/core" ;
2
2
import { InvocationContext } from "@loopback/context" ;
3
3
import {
4
4
DefaultCrudRepository ,
@@ -12,6 +12,10 @@ import {
12
12
EntityNotFoundError ,
13
13
} from "@loopback/repository" ;
14
14
15
+ export interface FilterOptions extends Options {
16
+ context : Context ;
17
+ }
18
+
15
19
/**
16
20
* This interface contains additional types added to FilterRepositoryMixin type
17
21
*/
@@ -90,10 +94,10 @@ export function FilterRepositoryMixin<
90
94
*/
91
95
createAll = async (
92
96
entities : DataObject < T > [ ] ,
93
- options ?: Options
97
+ options ?: FilterOptions
94
98
) => {
95
99
const filterContext = new InvocationContext (
96
- undefined as any ,
100
+ options ?. context as Context ,
97
101
this ,
98
102
"create" ,
99
103
Array . from ( arguments )
@@ -108,7 +112,7 @@ export function FilterRepositoryMixin<
108
112
/**
109
113
* Filter create() using createAll()
110
114
*/
111
- create = async ( entity : DataObject < T > , options ?: Options ) => {
115
+ create = async ( entity : DataObject < T > , options ?: FilterOptions ) => {
112
116
const result = await this . createAll ( [ entity ] , options ) ;
113
117
114
118
return result [ 0 ] ;
@@ -117,9 +121,9 @@ export function FilterRepositoryMixin<
117
121
/**
118
122
* Filter where and find all entities
119
123
*/
120
- find = async ( filter ?: Filter < T > , options ?: Options ) => {
124
+ find = async ( filter ?: Filter < T > , options ?: FilterOptions ) => {
121
125
const filterContext = new InvocationContext (
122
- undefined as any ,
126
+ options ?. context as Context ,
123
127
this ,
124
128
"read" ,
125
129
Array . from ( arguments )
@@ -144,9 +148,9 @@ export function FilterRepositoryMixin<
144
148
/**
145
149
* Filter where and find one entity
146
150
*/
147
- findOne = async ( filter ?: Filter < T > , options ?: Options ) => {
151
+ findOne = async ( filter ?: Filter < T > , options ?: FilterOptions ) => {
148
152
const filterContext = new InvocationContext (
149
- undefined as any ,
153
+ options ?. context as Context ,
150
154
this ,
151
155
"read" ,
152
156
Array . from ( arguments )
@@ -174,7 +178,7 @@ export function FilterRepositoryMixin<
174
178
findById = async (
175
179
id : ID ,
176
180
filter ?: FilterExcludingWhere < T > ,
177
- options ?: Options
181
+ options ?: FilterOptions
178
182
) => {
179
183
const result = await this . findOne (
180
184
{
@@ -194,9 +198,9 @@ export function FilterRepositoryMixin<
194
198
/**
195
199
* Filter where and count all entities
196
200
*/
197
- count = async ( where ?: Where < T > , options ?: Options ) => {
201
+ count = async ( where ?: Where < T > , options ?: FilterOptions ) => {
198
202
const filterContext = new InvocationContext (
199
- undefined as any ,
203
+ options ?. context as Context ,
200
204
this ,
201
205
"read" ,
202
206
Array . from ( arguments )
@@ -211,7 +215,7 @@ export function FilterRepositoryMixin<
211
215
/**
212
216
* Filter exists() using count()
213
217
*/
214
- exists = async ( id : ID , options ?: Options ) => {
218
+ exists = async ( id : ID , options ?: FilterOptions ) => {
215
219
const result = await this . count (
216
220
this . entityClass . buildWhereForId ( id ) ,
217
221
options
@@ -226,10 +230,10 @@ export function FilterRepositoryMixin<
226
230
updateAll = async (
227
231
data : DataObject < T > ,
228
232
where ?: Where < T > ,
229
- options ?: Options
233
+ options ?: FilterOptions
230
234
) => {
231
235
const filterContext = new InvocationContext (
232
- undefined as any ,
236
+ options ?. context as Context ,
233
237
this ,
234
238
"update" ,
235
239
Array . from ( arguments )
@@ -257,7 +261,7 @@ export function FilterRepositoryMixin<
257
261
updateById = async (
258
262
id : ID ,
259
263
data : DataObject < T > ,
260
- options ?: Options
264
+ options ?: FilterOptions
261
265
) => {
262
266
await this . updateAll (
263
267
data ,
@@ -269,7 +273,7 @@ export function FilterRepositoryMixin<
269
273
/**
270
274
* Filter update() using updateAll()
271
275
*/
272
- update = async ( entity : T , options ?: Options ) => {
276
+ update = async ( entity : T , options ?: FilterOptions ) => {
273
277
await this . updateAll (
274
278
entity ,
275
279
this . entityClass . buildWhereForId (
@@ -285,7 +289,7 @@ export function FilterRepositoryMixin<
285
289
replaceById = async (
286
290
id : ID ,
287
291
data : DataObject < T > ,
288
- options ?: Options
292
+ options ?: FilterOptions
289
293
) => {
290
294
await this . updateAll (
291
295
{
@@ -304,9 +308,9 @@ export function FilterRepositoryMixin<
304
308
/**
305
309
* Filter where and delete all entities
306
310
*/
307
- deleteAll = async ( where ?: Where < T > , options ?: Options ) => {
311
+ deleteAll = async ( where ?: Where < T > , options ?: FilterOptions ) => {
308
312
const filterContext = new InvocationContext (
309
- undefined as any ,
313
+ options ?. context as Context ,
310
314
this ,
311
315
"delete" ,
312
316
Array . from ( arguments )
@@ -321,7 +325,7 @@ export function FilterRepositoryMixin<
321
325
/**
322
326
* Filter delete() using deleteAll()
323
327
*/
324
- delete = async ( entity : T , options ?: Options ) => {
328
+ delete = async ( entity : T , options ?: FilterOptions ) => {
325
329
await this . deleteAll (
326
330
this . entityClass . buildWhereForId (
327
331
this . entityClass . getIdOf ( entity )
@@ -333,7 +337,7 @@ export function FilterRepositoryMixin<
333
337
/**
334
338
* Filter deleteById() using deleteAll()
335
339
*/
336
- deleteById = async ( id : ID , options ?: Options ) => {
340
+ deleteById = async ( id : ID , options ?: FilterOptions ) => {
337
341
await this . deleteAll (
338
342
this . entityClass . buildWhereForId ( id ) ,
339
343
options
0 commit comments