feat(api,templateActivator): обновлена логика templateActivator
This commit is contained in:
@@ -1,16 +1,43 @@
|
||||
using FluentValidation;
|
||||
using PARR.API.Contracts.V1.Requests;
|
||||
using PARR.Constants;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
|
||||
namespace PARR.API.Validators
|
||||
{
|
||||
public class TemplateActivatorRequestValidator : AbstractValidator<TemplateActivatorRequest>
|
||||
{
|
||||
public TemplateActivatorRequestValidator()
|
||||
public TemplateActivatorRequestValidator(
|
||||
ITemplateService templateService,
|
||||
IJobService jobService,
|
||||
IJobGroupService jobGroupService
|
||||
)
|
||||
{
|
||||
RuleFor(t => t.Action).Must(action =>
|
||||
Enum.IsDefined(typeof(TemplateActivatorActionsEnum), action)
|
||||
).WithMessage("Некорректное значение action");
|
||||
RuleFor(t => t.EntityType).Must(type =>
|
||||
Enum.IsDefined(typeof(SyncTaskEntityTypeEnum), type)
|
||||
).WithMessage("Некорректное значение EntityType");
|
||||
|
||||
RuleFor(t => t.EsppObject).Must(obj =>
|
||||
Enum.IsDefined(typeof(TemplateActivatorEsppObjectTypesEnum), obj)
|
||||
).WithMessage("Некорректное значение EsppObject");
|
||||
|
||||
RuleFor(t => t.Id)
|
||||
.MustAsync(async (entity, value, c) =>
|
||||
{
|
||||
switch (entity.EntityType)
|
||||
{
|
||||
case SyncTaskEntityTypeEnum.JobGroup:
|
||||
return await jobGroupService.GetAsync(value) != null;
|
||||
case SyncTaskEntityTypeEnum.Job:
|
||||
return await jobService.GetAsync(value) != null;
|
||||
case SyncTaskEntityTypeEnum.Template:
|
||||
return await templateService.GetAsync(value) != null;
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
.WithMessage("Некорректное значение Id");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user