1+ import 'reflect-metadata' ;
12import {
23 Repository ,
34 getMetadataArgsStorage ,
89 FindOneOptions ,
910 ObjectID ,
1011} from 'typeorm' ;
11- import { POLYMORPHIC_OPTIONS } from './contstants ' ;
12+ import { POLYMORPHIC_OPTIONS } from './constants ' ;
1213import {
1314 PolymorphicChildType ,
1415 PolymorphicParentType ,
@@ -53,25 +54,23 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
5354 }
5455
5556 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' ) ;
7574 }
7675
7776 protected isPolymorph ( ) : boolean {
@@ -94,7 +93,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
9493 }
9594
9695 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 ) ) ) ;
9897 }
9998
10099 public async hydrateOne ( entity : E ) : Promise < E > {
@@ -116,7 +115,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
116115 return values . reduce < E > ( ( e : E , vals : PolymorphicHydrationType ) => {
117116 const values =
118117 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 )
120119 : vals . values ;
121120 e [ vals . key ] =
122121 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> {
198197
199198 if ( Array . isArray ( entities ) ) {
200199 return Promise . all (
201- entities . map ( polymorph => {
200+ entities . map ( ( polymorph ) => {
202201 polymorph [ entityIdColumn ( options ) ] = entity [ entityIdColumn ( options ) ] ;
203202 polymorph [ entityTypeColumn ( options ) ] = this . metadata . targetName ;
204203
@@ -219,7 +218,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
219218 const results = await Promise . all (
220219 options . map (
221220 ( options : PolymorphicMetadataInterface ) =>
222- new Promise ( async resolve =>
221+ new Promise ( async ( resolve ) =>
223222 options . cascade
224223 ? resolve ( {
225224 key : options . propertyKey ,
@@ -253,7 +252,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
253252 await Promise . all (
254253 options . map (
255254 ( option : PolymorphicMetadataInterface ) =>
256- new Promise ( resolve => {
255+ new Promise ( ( resolve ) => {
257256 if ( ! option . deleteBeforeUpdate ) {
258257 return Promise . resolve ( ) ;
259258 }
@@ -325,7 +324,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
325324 public async save < T extends DeepPartial < E > > (
326325 entityOrEntities : T | Array < T > ,
327326 options ?: SaveOptions & { reload : false } ,
328- ) : Promise < T & E | Array < T & E > | T | Array < T > > {
327+ ) : Promise < ( T & E ) | Array < T & E > | T | Array < T > > {
329328 if ( ! this . isPolymorph ( ) ) {
330329 return Array . isArray ( entityOrEntities ) && options
331330 ? await super . save ( entityOrEntities , options )
@@ -399,7 +398,7 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
399398 const metadata = this . getPolymorphicMetadata ( ) ;
400399
401400 return Promise . all (
402- results . map ( entity => this . hydratePolymorphs ( entity , metadata ) ) ,
401+ results . map ( ( entity ) => this . hydratePolymorphs ( entity , metadata ) ) ,
403402 ) ;
404403 }
405404
@@ -437,9 +436,9 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
437436 idOrOptionsOrConditions as number | string | ObjectID | Date ,
438437 optionsOrConditions as FindConditions < E > | FindOneOptions < E > ,
439438 )
440- : super . findOne ( idOrOptionsOrConditions as
441- | FindConditions < E >
442- | FindOneOptions < E > ) ;
439+ : super . findOne (
440+ idOrOptionsOrConditions as FindConditions < E > | FindOneOptions < E > ,
441+ ) ;
443442 }
444443
445444 const entity =
@@ -452,9 +451,9 @@ export abstract class AbstractPolymorphicRepository<E> extends Repository<E> {
452451 idOrOptionsOrConditions as number | string | ObjectID | Date ,
453452 optionsOrConditions as FindConditions < E > | FindOneOptions < E > ,
454453 )
455- : await super . findOne ( idOrOptionsOrConditions as
456- | FindConditions < E >
457- | FindOneOptions < E > ) ;
454+ : await super . findOne (
455+ idOrOptionsOrConditions as FindConditions < E > | FindOneOptions < E > ,
456+ ) ;
458457
459458 if ( ! entity ) {
460459 return entity ;
0 commit comments