我正在尝试创建一个有权访问userRepository
的{{3}}。我也安装了typeorm-typedi-extensions
。
这不起作用:
@ValidatorConstraint({ async: true})
@Service()
export class IsUserAlreadyExistConstraint implements ValidatorConstraintInterface {
constructor(
@InjectRepository(User) private readonly userRepository: Repository<User>
) {}
async validate(email: any, args: ValidationArguments) {
console.log({ email })
console.log(this.userRepository)
const user = await this.userRepository.findOne({ email })
console.log({user});
if (user) return false;
return true;
}
}
export function IsUserAlreadyExist(validationOptions?: ValidationOptions) {
return function (object: Object, propertyName: string) {
registerDecorator({
target: object.constructor,
propertyName: propertyName,
options: validationOptions,
constraints: [],
validator: IsUserAlreadyExistConstraint
});
};
}