Skip to content

Commit

Permalink
Merge pull request #1333 from dineshsalunke/tree-repo-fix
Browse files Browse the repository at this point in the history
fix(provider): return proper repository
  • Loading branch information
kamilmysliwiec committed Aug 11, 2022
2 parents 78f30a7 + 5b666f2 commit 249edca
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/typeorm.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ export function createTypeOrmProviders(
return (entities || []).map((entity) => ({
provide: getRepositoryToken(entity, dataSource),
useFactory: (dataSource: DataSource) => {
return dataSource.options.type === 'mongodb'
? dataSource.getMongoRepository(entity)
: dataSource.getRepository(entity);
const enitityMetadata = dataSource.entityMetadatas.find((meta) => meta.target === entity)
const isTreeEntity = typeof enitityMetadata?.treeType !== 'undefined'
return isTreeEntity
? dataSource.getTreeRepository(entity)
: dataSource.options.type === 'mongodb'
? dataSource.getMongoRepository(entity)
: dataSource.getRepository(entity);
},
inject: [getDataSourceToken(dataSource)],
/**
Expand Down

0 comments on commit 249edca

Please sign in to comment.