1
+ import 'reflect-metadata' ;
1
2
import {
2
3
Repository ,
3
4
getMetadataArgsStorage ,
8
9
FindOneOptions ,
9
10
ObjectID ,
10
11
} from 'typeorm' ;
11
- import { POLYMORPHIC_OPTIONS } from './contstants ' ;
12
+ import { POLYMORPHIC_OPTIONS } from './constants ' ;
12
13
import {
13
14
PolymorphicChildType ,
14
15
PolymorphicParentType ,
@@ -53,25 +54,23 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
53
54
}
54
55
55
56
return keys
56
- . map (
57
- ( key : string ) : PolymorphicMetadataInterface | undefined => {
58
- const data : PolymorphicMetadataOptionsInterface & {
59
- propertyKey : string ;
60
- } = Reflect . getMetadata (
61
- key ,
62
- ( this . metadata . target as Function ) [ 'prototype' ] ,
63
- ) ;
64
-
65
- if ( typeof data === 'object' ) {
66
- const classType = data . classType ( ) ;
67
- return {
68
- ...data ,
69
- classType,
70
- } ;
71
- }
72
- } ,
73
- )
74
- . filter ( val => typeof val !== 'undefined' ) ;
57
+ . map ( ( key : string ) : PolymorphicMetadataInterface | undefined => {
58
+ const data : PolymorphicMetadataOptionsInterface & {
59
+ propertyKey : string ;
60
+ } = Reflect . getMetadata (
61
+ key ,
62
+ ( this . metadata . target as Function ) [ 'prototype' ] ,
63
+ ) ;
64
+
65
+ if ( typeof data === 'object' ) {
66
+ const classType = data . classType ( ) ;
67
+ return {
68
+ ...data ,
69
+ classType,
70
+ } ;
71
+ }
72
+ } )
73
+ . filter ( ( val ) => typeof val !== 'undefined' ) ;
75
74
}
76
75
77
76
protected isPolymorph ( ) : boolean {
@@ -94,7 +93,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
94
93
}
95
94
96
95
public async hydrateMany ( entities : E [ ] ) : Promise < E [ ] > {
97
- return Promise . all ( entities . map ( ent => this . hydrateOne ( ent ) ) ) ;
96
+ return Promise . all ( entities . map ( ( ent ) => this . hydrateOne ( ent ) ) ) ;
98
97
}
99
98
100
99
public async hydrateOne ( entity : E ) : Promise < E > {
@@ -116,7 +115,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
116
115
return values . reduce < E > ( ( e : E , vals : PolymorphicHydrationType ) => {
117
116
const values =
118
117
vals . type === 'parent' && Array . isArray ( vals . values )
119
- ? vals . values . filter ( v => typeof v !== 'undefined' && v !== null )
118
+ ? vals . values . filter ( ( v ) => typeof v !== 'undefined' && v !== null )
120
119
: vals . values ;
121
120
e [ vals . key ] =
122
121
vals . type === 'parent' && Array . isArray ( values ) ? values [ 0 ] : values ; // TODO should be condition for !hasMany
@@ -198,7 +197,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
198
197
199
198
if ( Array . isArray ( entities ) ) {
200
199
return Promise . all (
201
- entities . map ( polymorph => {
200
+ entities . map ( ( polymorph ) => {
202
201
polymorph [ entityIdColumn ( options ) ] = entity [ entityIdColumn ( options ) ] ;
203
202
polymorph [ entityTypeColumn ( options ) ] = this . metadata . targetName ;
204
203
@@ -219,7 +218,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
219
218
const results = await Promise . all (
220
219
options . map (
221
220
( options : PolymorphicMetadataInterface ) =>
222
- new Promise ( async resolve =>
221
+ new Promise ( async ( resolve ) =>
223
222
options . cascade
224
223
? resolve ( {
225
224
key : options . propertyKey ,
@@ -253,7 +252,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
253
252
await Promise . all (
254
253
options . map (
255
254
( option : PolymorphicMetadataInterface ) =>
256
- new Promise ( resolve => {
255
+ new Promise ( ( resolve ) => {
257
256
if ( ! option . deleteBeforeUpdate ) {
258
257
return Promise . resolve ( ) ;
259
258
}
@@ -325,7 +324,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
325
324
public async save < T extends DeepPartial < E > > (
326
325
entityOrEntities : T | Array < T > ,
327
326
options ?: SaveOptions & { reload : false } ,
328
- ) : Promise < T & E | Array < T & E > | T | Array < T > > {
327
+ ) : Promise < ( T & E ) | Array < T & E > | T | Array < T > > {
329
328
if ( ! this . isPolymorph ( ) ) {
330
329
return Array . isArray ( entityOrEntities ) && options
331
330
? await super . save ( entityOrEntities , options )
@@ -399,7 +398,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
399
398
const metadata = this . getPolymorphicMetadata ( ) ;
400
399
401
400
return Promise . all (
402
- results . map ( entity => this . hydratePolymorphs ( entity , metadata ) ) ,
401
+ results . map ( ( entity ) => this . hydratePolymorphs ( entity , metadata ) ) ,
403
402
) ;
404
403
}
405
404
@@ -437,9 +436,9 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
437
436
idOrOptionsOrConditions as number | string | ObjectID | Date ,
438
437
optionsOrConditions as FindConditions < E > | FindOneOptions < E > ,
439
438
)
440
- : super . findOne ( idOrOptionsOrConditions as
441
- | FindConditions < E >
442
- | FindOneOptions < E > ) ;
439
+ : super . findOne (
440
+ idOrOptionsOrConditions as FindConditions < E > | FindOneOptions < E > ,
441
+ ) ;
443
442
}
444
443
445
444
const entity =
@@ -452,9 +451,9 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
452
451
idOrOptionsOrConditions as number | string | ObjectID | Date ,
453
452
optionsOrConditions as FindConditions < E > | FindOneOptions < E > ,
454
453
)
455
- : await super . findOne ( idOrOptionsOrConditions as
456
- | FindConditions < E >
457
- | FindOneOptions < E > ) ;
454
+ : await super . findOne (
455
+ idOrOptionsOrConditions as FindConditions < E > | FindOneOptions < E > ,
456
+ ) ;
458
457
459
458
if ( ! entity ) {
460
459
return entity ;
0 commit comments