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:
Charles Bochet
2024-07-23 14:13:16 +02:00
committed by GitHub
parent 794e73eeb6
commit 6c34ef9a14
23 changed files with 205 additions and 1672 deletions

View File

@ -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`;
}