@@ -22,6 +22,16 @@ export interface FilterRepository<
22
22
> { }
23
23
24
24
/**
25
+ * +--------+
26
+ * | create |
27
+ * +----+---+
28
+ * |
29
+ * |
30
+ * +----v------+
31
+ * | createAll |
32
+ * +-----------+
33
+ *
34
+ *
25
35
* +----------+ +--------+
26
36
* | findById | | exists |
27
37
* +----+-----+ +---+----+
@@ -59,6 +69,10 @@ export function FilterRepositoryMixin<
59
69
ID ,
60
70
Relations extends object = { }
61
71
> ( config : {
72
+ models : (
73
+ context : InvocationContext ,
74
+ models : DataObject < T > [ ]
75
+ ) => Promise < ( DataObject < T > | undefined ) [ ] > ;
62
76
where : ( context : InvocationContext , where : Where < T > ) => Promise < Where < T > > ;
63
77
fields : (
64
78
context : InvocationContext ,
@@ -71,6 +85,36 @@ export function FilterRepositoryMixin<
71
85
class MixedRepository
72
86
extends superClass
73
87
implements FilterRepository < T , ID , Relations > {
88
+ /**
89
+ * Map models and create all entities
90
+ */
91
+ createAll = async (
92
+ entities : DataObject < T > [ ] ,
93
+ options ?: Options
94
+ ) => {
95
+ const filterContext = new InvocationContext (
96
+ undefined as any ,
97
+ this ,
98
+ "create" ,
99
+ Array . from ( arguments )
100
+ ) ;
101
+
102
+ const mappedEntities : any [ ] = (
103
+ await config . models ( filterContext , entities || [ ] )
104
+ ) . filter ( ( entity ) => entity ) ;
105
+
106
+ return await super . createAll ( mappedEntities , options ) ;
107
+ } ;
108
+
109
+ /**
110
+ * Filter create() using createAll()
111
+ */
112
+ create = async ( entity : DataObject < T > , options ?: Options ) => {
113
+ const result = await this . createAll ( [ entity ] , options ) ;
114
+
115
+ return result [ 0 ] ;
116
+ } ;
117
+
74
118
/**
75
119
* Filter where and find all entities
76
120
*/
@@ -126,7 +170,7 @@ export function FilterRepositoryMixin<
126
170
} ;
127
171
128
172
/**
129
- * History findById() using findOne()
173
+ * Filter findById() using findOne()
130
174
*/
131
175
findById = async (
132
176
id : ID ,
@@ -166,7 +210,7 @@ export function FilterRepositoryMixin<
166
210
} ;
167
211
168
212
/**
169
- * History exists() using count()
213
+ * Filter exists() using count()
170
214
*/
171
215
exists = async ( id : ID , options ?: Options ) => {
172
216
const result = await this . count (
@@ -178,7 +222,7 @@ export function FilterRepositoryMixin<
178
222
} ;
179
223
180
224
/**
181
- * Filter where and update all entities
225
+ * Filter where, Map models and update all entities
182
226
*/
183
227
updateAll = async (
184
228
data : DataObject < T > ,
@@ -192,15 +236,24 @@ export function FilterRepositoryMixin<
192
236
Array . from ( arguments )
193
237
) ;
194
238
239
+ const mappedModel = (
240
+ await config . models ( filterContext , [ data ] )
241
+ ) [ 0 ] ;
242
+ if ( ! mappedModel ) {
243
+ return {
244
+ count : 0 ,
245
+ } ;
246
+ }
247
+
195
248
return await super . updateAll (
196
- data ,
249
+ mappedModel ,
197
250
await config . where ( filterContext , where || { } ) ,
198
251
options
199
252
) ;
200
253
} ;
201
254
202
255
/**
203
- * History updateById() using updateAll()
256
+ * Filter updateById() using updateAll()
204
257
*/
205
258
updateById = async (
206
259
id : ID ,
@@ -215,7 +268,7 @@ export function FilterRepositoryMixin<
215
268
} ;
216
269
217
270
/**
218
- * History update() using updateAll()
271
+ * Filter update() using updateAll()
219
272
*/
220
273
update = async ( entity : T , options ?: Options ) => {
221
274
await this . updateAll (
@@ -228,7 +281,7 @@ export function FilterRepositoryMixin<
228
281
} ;
229
282
230
283
/**
231
- * History replaceById() using updateAll()
284
+ * Filter replaceById() using updateAll()
232
285
*/
233
286
replaceById = async (
234
287
id : ID ,
@@ -267,7 +320,7 @@ export function FilterRepositoryMixin<
267
320
} ;
268
321
269
322
/**
270
- * History delete() using deleteAll()
323
+ * Filter delete() using deleteAll()
271
324
*/
272
325
delete = async ( entity : T , options ?: Options ) => {
273
326
await this . deleteAll (
@@ -279,7 +332,7 @@ export function FilterRepositoryMixin<
279
332
} ;
280
333
281
334
/**
282
- * History deleteById() using deleteAll()
335
+ * Filter deleteById() using deleteAll()
283
336
*/
284
337
deleteById = async ( id : ID , options ?: Options ) => {
285
338
await this . deleteAll (
0 commit comments