mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 10:43:13 +00:00
Scheduled still requires a concrete date, and Incomplete/Pending with a date must promote even when only lifecycleStatus is sent.
47 lines
1.6 KiB
C#
47 lines
1.6 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Data.SeaHavenIndustries.Enums;
|
|
using SeaHaven.Services.Exceptions;
|
|
|
|
namespace SeaHaven.Services.Helpers
|
|
{
|
|
public static class WorkOrderBoardCreateLifecycleRules
|
|
{
|
|
private static readonly HashSet<LifecycleStatus> AllowedCreateStatuses =
|
|
[
|
|
LifecycleStatus.Incomplete,
|
|
LifecycleStatus.Pending,
|
|
LifecycleStatus.Scheduled,
|
|
];
|
|
|
|
public static void ApplyRequestedOrInitialLifecycleStatus(
|
|
WorkOrder workOrder,
|
|
LifecycleStatus? requested,
|
|
DateTime? scheduledDate,
|
|
bool? scheduleWeekOnly)
|
|
{
|
|
if (!requested.HasValue)
|
|
{
|
|
WorkOrderBoardFieldMutations.SetInitialLifecycleStatus(workOrder);
|
|
return;
|
|
}
|
|
|
|
if (!AllowedCreateStatuses.Contains(requested.Value))
|
|
{
|
|
throw new WorkOrderBoardValidationException(
|
|
"InvalidLifecycleStatus",
|
|
"lifecycleStatus must be Incomplete, Pending, or Scheduled at create.");
|
|
}
|
|
|
|
if (requested == LifecycleStatus.Scheduled
|
|
&& !WorkOrderBoardMutationRules.HasConcreteSchedule(scheduledDate, scheduleWeekOnly))
|
|
{
|
|
throw new WorkOrderBoardValidationException(
|
|
"ScheduledRequiresDate",
|
|
"Scheduled requires a concrete scheduledDate when scheduleWeekOnly is not true.");
|
|
}
|
|
|
|
workOrder.LifecycleStatus = requested.Value;
|
|
workOrder.Status = WorkOrderDerivedFields.GetLifecycleStatusLabel(requested.Value);
|
|
}
|
|
}
|
|
}
|