39 lines
1.7 KiB
C#
39 lines
1.7 KiB
C#
using AutobusApi.Domain.Enums;
|
|
using FluentValidation;
|
|
|
|
namespace AutobusApi.Application.Employees.Commands.CreateEmployee;
|
|
|
|
public class CreateEmployeeCommandValidator : AbstractValidator<CreateEmployeeCommand>
|
|
{
|
|
public CreateEmployeeCommandValidator()
|
|
{
|
|
RuleFor(v => v.Email)
|
|
.NotEmpty().WithMessage("Email address is required.")
|
|
.Matches(@"\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b").WithMessage("Email address is invalid.");
|
|
|
|
RuleFor(v => v.Password)
|
|
.NotEmpty().WithMessage("Password is required.")
|
|
.MinimumLength(8).WithMessage("Password must be at least 8 characters long.")
|
|
.MaximumLength(64).WithMessage("Password must be at most 64 characters long.")
|
|
.Matches(@"(?=.*[A-Z]).*").WithMessage("Password must contain at least one uppercase letter.")
|
|
.Matches(@"(?=.*[a-z]).*").WithMessage("Password must contain at least one lowercase letter.")
|
|
.Matches(@"(?=.*[\d]).*").WithMessage("Password must contain at least one digit.")
|
|
.Matches(@"(?=.*[!@#$%^&*()]).*").WithMessage("Password must contain at least one of the following special charactters: !@#$%^&*().");
|
|
|
|
RuleFor(v => v.FirstName).MinimumLength(2).MaximumLength(32);
|
|
|
|
RuleFor(v => v.LastName).MinimumLength(2).MaximumLength(32);
|
|
|
|
RuleFor(v => v.Patronymic).MinimumLength(2).MaximumLength(32);
|
|
|
|
RuleFor(v => v.Sex).Must(value => Enum.TryParse<Sex>(value, true, out _));
|
|
|
|
RuleForEach(v => v.Documents).ChildRules(document =>
|
|
{
|
|
document.RuleFor(v => v.Type).Must(value => Enum.TryParse<EmployeeDocumentType>(value, true, out _));
|
|
|
|
document.RuleFor(v => v.Information).MinimumLength(2).MaximumLength(256);
|
|
});
|
|
}
|
|
}
|