Files
nashel-backend/src/Modules/Identity/Application/Validators/RegisterUserCommandValidator.cs
Халимов Рустам 1e72d006c4 Страница профиля
2026-02-13 14:24:01 +03:00

32 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using FluentValidation;
using Nashel.Modules.Identity.Application.Commands;
using Nashel.Modules.Identity.Domain.Enums;
namespace Nashel.Modules.Identity.Application.Validators;
public class RegisterUserCommandValidator : AbstractValidator<RegisterUserCommand>
{
public RegisterUserCommandValidator()
{
RuleFor(x => x.Phone)
.NotEmpty().WithMessage("Телефон обязателен")
.Matches(@"^\+\d{11,15}$").WithMessage("Формат телефона должен быть E.164 (начинаться с +, 11-15 цифр)");
RuleFor(x => x.Password)
.NotEmpty().WithMessage("Пароль обязателен")
.MinimumLength(6).WithMessage("Пароль должен быть не менее 6 символов");
RuleFor(x => x.FirstName)
.NotEmpty().WithMessage("Имя обязательно")
.MinimumLength(2).WithMessage("Имя должно содержать минимум 2 символа");
RuleFor(x => x.LastName)
.NotEmpty().WithMessage("Фамилия обязательна")
.MinimumLength(2).WithMessage("Фамилия должна содержать минимум 2 символа");
RuleFor(x => x.CompanyName)
.NotEmpty().WithMessage("Название компании обязательно для юридических лиц")
.When(x => x.Role == Role.Company);
}
}