Наличие такой сущности:
import { UniqueOrganizationPrincipal } from './constraints/unique-organization-principal';
import { Role } from './role.entity';
@Entity()
export class UserOrganization {
@ManyToOne(type => Role, role => role.userOrganizations, { nullable: false, eager: true })
@UniqueOrganizationPrincipal()
role: Role;
... other fields ...
}
и пользовательского класса проверки
import { Role } from '../role.entity';
import { UserOrganizationService } from '../user-organization.service';
@ValidatorConstraint({ async: true })
@Injectable()
export class UniqueOrganizationPrincipalConstraint implements ValidatorConstraintInterface {
constructor(
@Inject('UserOrganizationService') private readonly userService: UserOrganizationService
) { }
async validate(role: Role, args: ValidationArguments) {
.....
}
defaultMessage() {
return 'error here';
}
}
export function UniqueOrganizationPrincipal(validationOptions?: ValidationOptions) {
return (object: object, propertyName: string) => {
registerDecorator({
target: object.constructor,
propertyName,
options: validationOptions,
constraints: [],
validator: UniqueOrganizationPrincipalConstraint
});
};
}
и службы, которая внедряет хранилище сущности
@Injectable()
export class UserOrganizationService {
constructor(
@InjectRepository(UserOrganization)
private readonly userOrganizationRepository: Repository<UserOrganization>
) {}
Iполучаю эту ошибку:
/project/node_modules/@nestjs/typeorm/dist/common/typeorm.utils.js:14
throw new circular_dependency_exception_1.CircularDependencyException('@InjectRepository()');
^
Error: A circular dependency has been detected inside @InjectRepository(). Please, make sure that each side of a bidirectional relationships are decorated with "forwardRef()". Also, try to eliminate barrel files because they can lead to an unexpected behavior too.
at Object.getRepositoryToken (/project/node_modules/@nestjs/typeorm/dist/common/typeorm.utils.js:14:15)
at Object.exports.InjectRepository (/project/node_modules/@nestjs/typeorm/dist/common/typeorm.decorators.js:6:130)
at Object.<anonymous> (/project/src/user/user-organization.service.ts:14:6)
at Module._compile (internal/modules/cjs/loader.js:805:30)
at Module.m._compile (/project/node_modules/ts-node/src/index.ts:439:23)
at Module._extensions..js (internal/modules/cjs/loader.js:816:10)
at Object.require.extensions.(anonymous function) [as .ts] (/project/node_modules/ts-node/src/index.ts:442:12)
at Module.load (internal/modules/cjs/loader.js:672:32)
at tryModuleLoad (internal/modules/cjs/loader.js:612:12)
at Function.Module._load (internal/modules/cjs/loader.js:604:3)
, поскольку для моей логики проверки мне нужно выполнить запрос и, по крайней мере, внедрить службу или репозиторий, как мне его получить?