feat(api): jobGroup - управление автораспределением
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PARR.API.Contracts.V1.Requests;
|
||||
using PARR.DAL.Contracts;
|
||||
using PARR.DAL.Services.Interfaces;
|
||||
using PARR.DAL.Services.Interfaces.Job;
|
||||
using PARR.DAL.Services.Interfaces.Schedule;
|
||||
using PARR.DAL.Services.Interfaces.Unit;
|
||||
@@ -14,7 +15,8 @@ namespace PARR.API.Validators
|
||||
IJobGroupTypeService jobGroupTypeService,
|
||||
IUnitFieldService unitFieldService,
|
||||
IScheduleExcludeTypeService scheduleExcludeTypeService,
|
||||
IScheduleExcludeTypeCalendarService scheduleExcludeTypeCalendarService
|
||||
IScheduleExcludeTypeCalendarService scheduleExcludeTypeCalendarService,
|
||||
IDistributionPeriodService distributionPeriodService
|
||||
)
|
||||
{
|
||||
RuleFor(t => t.Name)
|
||||
@@ -91,6 +93,35 @@ namespace PARR.API.Validators
|
||||
})
|
||||
.WithMessage("Некорректное значение");
|
||||
|
||||
RuleFor(t => t.DistributionConfig)
|
||||
.Must((entity, value, c) =>
|
||||
{
|
||||
// если включено автораспределение, должны быть настройки
|
||||
if (entity.IsAutoDistributionEnabled && value != null)
|
||||
return true;
|
||||
|
||||
// если выкл автораспределение, то валидно
|
||||
if (!entity.IsAutoDistributionEnabled)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}).WithMessage("Отсутствуют настройки автораспределения");
|
||||
|
||||
RuleFor(t => t.DistributionConfig)
|
||||
.MustAsync(async (entity, value, c) =>
|
||||
{
|
||||
// если есть настройка периода, проверить что она валидна
|
||||
var periodId = value?.DistributionPeriodId;
|
||||
|
||||
if (periodId.HasValue)
|
||||
{
|
||||
var exist = await distributionPeriodService.GetAsync(periodId.Value);
|
||||
|
||||
return exist != null;
|
||||
}
|
||||
|
||||
return true;
|
||||
}).WithMessage("Некорректное значение периода распределения");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user