-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
fangzhipeng
committed
Aug 23, 2020
1 parent
cf7bd2f
commit 1018a7e
Showing
2 changed files
with
43 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {EntityClassOrSchema} from "./interfaces/entity-class-or-schema.type"; | ||
import {AbstractRepository, getMetadataArgsStorage, Repository} from "typeorm"; | ||
|
||
|
||
export function getCustomRepositoryEntity(entities: EntityClassOrSchema[]): Array<EntityClassOrSchema> { | ||
let customRepositoryEntities = new Array<EntityClassOrSchema>(); | ||
for (let entity of entities) { | ||
if ( | ||
entity instanceof Function && | ||
(entity.prototype instanceof Repository || | ||
entity.prototype instanceof AbstractRepository) | ||
) { | ||
const entityRepositoryMetadataArgs = getMetadataArgsStorage().entityRepositories.find( | ||
(repository) => { | ||
return ( | ||
repository.target === | ||
(entity instanceof Function | ||
? entity | ||
: (entity as any).constructor) | ||
); | ||
}, | ||
); | ||
if (entityRepositoryMetadataArgs) { | ||
if ( | ||
entities.indexOf(<EntityClassOrSchema>entityRepositoryMetadataArgs.entity) === -1 | ||
) { | ||
customRepositoryEntities.push(<EntityClassOrSchema>entityRepositoryMetadataArgs.entity); | ||
} | ||
} | ||
} | ||
} | ||
return customRepositoryEntities; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters