@@ -182,102 +182,6 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
182
182
) ;
183
183
}
184
184
185
- private async savePolymorhic (
186
- entity : E ,
187
- options : PolymorphicMetadataInterface ,
188
- ) : Promise < PolymorphicChildInterface [ ] | PolymorphicChildInterface > {
189
- const entities :
190
- | PolymorphicChildInterface
191
- | PolymorphicChildInterface [ ]
192
- | undefined = entity [ options . propertyKey ] ;
193
-
194
- if ( ! entities ) {
195
- return undefined ;
196
- }
197
-
198
- if ( Array . isArray ( entities ) ) {
199
- return Promise . all (
200
- entities . map ( ( polymorph ) => {
201
- polymorph [ entityIdColumn ( options ) ] = entity [ entityIdColumn ( options ) ] ;
202
- polymorph [ entityTypeColumn ( options ) ] = this . metadata . targetName ;
203
-
204
- return this . manager . save ( polymorph ) ;
205
- } ) ,
206
- ) ;
207
- } else {
208
- entities [ entityIdColumn ( options ) ] = entity [ entityIdColumn ( options ) ] ;
209
- entities [ entityTypeColumn ( options ) ] = this . metadata . targetName ;
210
- return this . manager . save ( entities ) ;
211
- }
212
- }
213
-
214
- private async savePolymorphs (
215
- entity : E ,
216
- options : PolymorphicMetadataInterface [ ] ,
217
- ) : Promise < E > {
218
- const results = await Promise . all (
219
- options . map (
220
- ( options : PolymorphicMetadataInterface ) =>
221
- new Promise ( async ( resolve ) =>
222
- options . cascade
223
- ? resolve ( {
224
- key : options . propertyKey ,
225
- entities : await this . savePolymorhic ( entity , options ) ,
226
- } )
227
- : resolve ( undefined ) ,
228
- ) ,
229
- ) ,
230
- ) ;
231
-
232
- results . forEach (
233
- (
234
- result :
235
- | { key : string ; entities : PolymorphicChildInterface [ ] }
236
- | undefined ,
237
- ) => {
238
- if ( ! result ) {
239
- return ;
240
- }
241
- entity [ result . key ] = result . entities ;
242
- } ,
243
- ) ;
244
-
245
- return entity ;
246
- }
247
-
248
- private async deletePolymorphs (
249
- entity : E ,
250
- options : PolymorphicMetadataInterface [ ] ,
251
- ) : Promise < void | never > {
252
- await Promise . all (
253
- options . map (
254
- ( option : PolymorphicMetadataInterface ) =>
255
- new Promise ( ( resolve ) => {
256
- if ( ! option . deleteBeforeUpdate ) {
257
- return Promise . resolve ( ) ;
258
- }
259
-
260
- const entityTypes = Array . isArray ( option . classType )
261
- ? option . classType
262
- : [ option . classType ] ;
263
-
264
- resolve (
265
- Promise . all (
266
- entityTypes . map ( ( type : ( ) => Function | Function [ ] ) => {
267
- const repository = this . findRepository ( type ) ;
268
-
269
- repository . delete ( {
270
- [ entityTypeColumn ( option ) ] : type ,
271
- [ entityIdColumn ( option ) ] : entity [ PrimaryColumn ( option ) ] ,
272
- } ) ;
273
- } ) ,
274
- ) ,
275
- ) ;
276
- } ) ,
277
- ) ,
278
- ) ;
279
- }
280
-
281
185
private findRepository (
282
186
entityType : Function ,
283
187
) : Repository < PolymorphicChildInterface | never > {
0 commit comments