1
1
import { Provider } from '@nestjs/common' ;
2
- import { DataSource , DataSourceOptions , getMetadataArgsStorage } from 'typeorm' ;
3
- import { getDataSourceToken , getRepositoryToken } from './common/typeorm.utils' ;
2
+ import { DataSource , DataSourceOptions , EntityManager , getMetadataArgsStorage } from 'typeorm' ;
3
+ import { getDataSourceToken , getEntityManagerToken , getRepositoryToken } from './common/typeorm.utils' ;
4
4
import { EntityClassOrSchema } from './interfaces/entity-class-or-schema.type' ;
5
5
6
6
export function createTypeOrmProviders (
@@ -9,16 +9,16 @@ export function createTypeOrmProviders(
9
9
) : Provider [ ] {
10
10
return ( entities || [ ] ) . map ( ( entity ) => ( {
11
11
provide : getRepositoryToken ( entity , dataSource ) ,
12
- useFactory : ( dataSource : DataSource ) => {
13
- const enitityMetadata = dataSource . entityMetadatas . find ( ( meta ) => meta . target === entity )
12
+ useFactory : ( entityManager : EntityManager ) => {
13
+ const enitityMetadata = entityManager . connection . entityMetadatas . find ( ( meta ) => meta . target === entity )
14
14
const isTreeEntity = typeof enitityMetadata ?. treeType !== 'undefined'
15
- return isTreeEntity
16
- ? dataSource . getTreeRepository ( entity )
17
- : dataSource . options . type === 'mongodb'
18
- ? dataSource . getMongoRepository ( entity )
19
- : dataSource . getRepository ( entity ) ;
15
+ return isTreeEntity
16
+ ? entityManager . getTreeRepository ( entity )
17
+ : entityManager . connection . options . type === 'mongodb'
18
+ ? entityManager . getMongoRepository ( entity )
19
+ : entityManager . getRepository ( entity ) ;
20
20
} ,
21
- inject : [ getDataSourceToken ( dataSource ) ] ,
21
+ inject : [ getEntityManagerToken ( dataSource ) ] ,
22
22
/**
23
23
* Extra property to workaround dynamic modules serialisation issue
24
24
* that occurs when "TypeOrm#forFeature()" method is called with the same number
0 commit comments