mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 14:13:12 +00:00
Add set-once IsAddOn with server cutoff at create, board DTO exposure, legacy type-7 backfill, and Types=AddOn search compat. Aligns with FE PR #61 frozen contract.
45 lines
1.9 KiB
C#
45 lines
1.9 KiB
C#
using Data.SeaHavenIndustries.Enums;
|
|
|
|
namespace SeaHaven.Services.Helpers
|
|
{
|
|
public static class WorkOrderBoardMutationRules
|
|
{
|
|
private static readonly HashSet<LifecycleStatus?> ReadOnlyStatuses =
|
|
LifecycleStatusSets.Terminal.Cast<LifecycleStatus?>().ToHashSet();
|
|
|
|
public static bool IsReadOnly(LifecycleStatus? status) => ReadOnlyStatuses.Contains(status);
|
|
|
|
public static bool ShouldBlockStatusChangeWhenPastDue(string field, bool isPastDue)
|
|
=> field.Equals(WorkOrderBoardFieldNames.LifecycleStatus, StringComparison.OrdinalIgnoreCase) && isPastDue;
|
|
|
|
/// <summary>
|
|
/// SHOC rule: Incomplete + specific scheduled date + assignee → Scheduled.
|
|
/// Week-only targets do not auto-schedule (same as <see cref="WorkOrderDerivedFields.ApplyAutoScheduleIfEligible"/>).
|
|
/// </summary>
|
|
public static bool ShouldAutoSchedule(
|
|
LifecycleStatus? status,
|
|
DateTime? scheduledDate,
|
|
string? assignTo,
|
|
bool? scheduleWeekOnly = null)
|
|
=> status == LifecycleStatus.Incomplete
|
|
&& scheduleWeekOnly != true
|
|
&& scheduledDate.HasValue
|
|
&& !string.IsNullOrWhiteSpace(assignTo);
|
|
|
|
public static bool IsReschedule(DateTime? previousDate, DateTime? newDate)
|
|
=> previousDate.HasValue
|
|
&& newDate.HasValue
|
|
&& previousDate.Value.Date != newDate.Value.Date;
|
|
|
|
public static DateOnly? ComputeOriginalWeek(DateTime? scheduledDate)
|
|
=> scheduledDate.HasValue
|
|
? DateOnly.FromDateTime(GetWeekStartMonday(scheduledDate.Value))
|
|
: null;
|
|
|
|
public static DateTime GetWeekStartMonday(DateTime date)
|
|
{
|
|
var diff = (7 + (date.DayOfWeek - DayOfWeek.Monday)) % 7;
|
|
return date.Date.AddDays(-diff);
|
|
}
|
|
}
|
|
}
|