mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-01 14:33:15 +00:00
39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
using Data.SeaHavenIndustries.Enums;
|
|
|
|
namespace SeaHaven.Services.Helpers
|
|
{
|
|
public static class WorkOrderBoardMutationRules
|
|
{
|
|
public static bool IsReadOnly(LifecycleStatus? status)
|
|
=> status.HasValue && LifecycleStatusSets.Terminal.Contains(status);
|
|
|
|
public static bool ShouldBlockStatusChangeWhenPastDue(string field, bool isPastDue)
|
|
=> field.Equals(WorkOrderBoardFieldNames.LifecycleStatus, StringComparison.OrdinalIgnoreCase) && isPastDue;
|
|
|
|
public static bool ShouldAutoSchedule(
|
|
LifecycleStatus? status,
|
|
DateTime? scheduledDate,
|
|
string? assignTo,
|
|
bool? scheduleWeekOnly = null)
|
|
=> status == LifecycleStatus.Incomplete
|
|
&& scheduledDate.HasValue
|
|
&& !string.IsNullOrWhiteSpace(assignTo)
|
|
&& scheduleWeekOnly != true;
|
|
|
|
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;
|
|
|
|
private static DateTime GetWeekStartMonday(DateTime date)
|
|
{
|
|
var diff = (7 + (date.DayOfWeek - DayOfWeek.Monday)) % 7;
|
|
return date.Date.AddDays(-diff);
|
|
}
|
|
}
|
|
}
|