Simplify ORM (#6373)
This PR refactors the ORM-Manager to simplify and unify the datasource creation. I'm deprecating all usages if InjectWorkspaceDatasource and InjectWorkspaceRepository as we can't be sure they are up-to-date
This commit is contained in:
@ -1,24 +0,0 @@
|
||||
import { EntityClassOrSchema } from '@nestjs/typeorm/dist/interfaces/entity-class-or-schema.type';
|
||||
|
||||
import { EntitySchema, Repository } from 'typeorm';
|
||||
|
||||
export function getWorkspaceRepositoryToken(
|
||||
entity: EntityClassOrSchema,
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
): Function | string {
|
||||
if (entity === null || entity === undefined) {
|
||||
throw new Error('Circular dependency @InjectWorkspaceRepository()');
|
||||
}
|
||||
|
||||
if (entity instanceof Function && entity.prototype instanceof Repository) {
|
||||
return entity;
|
||||
}
|
||||
|
||||
if (entity instanceof EntitySchema) {
|
||||
return `${
|
||||
entity.options.target ? entity.options.target.name : entity.options.name
|
||||
}WorkspaceRepository`;
|
||||
}
|
||||
|
||||
return `${entity.name}WorkspaceRepository`;
|
||||
}
|
||||
Reference in New Issue
Block a user