mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-03 10:23:28 +00:00
Expand LifecycleStatus (EnRoute, OnSite, Rescheduled, Pending, PendingQuote) and WorkOrderType (Reactive, AddOn) to match the frontend prototype. Add FE label round-trip via LifecycleStatusMapper/WorkOrderTypeMapper, update derived fields, mutation rules and board unscheduled filter, and reactivate [Authorize] on WorkOrderController. Fix pre-existing dayGroup test expectation.
55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using Data.SeaHavenIndustries.Enums;
|
||
|
||
namespace SeaHaven.Services.Helpers
|
||
{
|
||
public static class WorkOrderDerivedFields
|
||
{
|
||
public static bool IsPastDue(
|
||
DateTime? scheduledDate,
|
||
LifecycleStatus? lifecycleStatus,
|
||
DateTime? utcNow = null)
|
||
{
|
||
if (!scheduledDate.HasValue)
|
||
return false;
|
||
|
||
if (LifecycleStatusMapper.IsTerminal(lifecycleStatus))
|
||
return false;
|
||
|
||
var today = (utcNow ?? DateTime.UtcNow).Date;
|
||
return scheduledDate.Value.Date < today;
|
||
}
|
||
|
||
public static bool IsTerminal(LifecycleStatus? lifecycleStatus)
|
||
=> LifecycleStatusMapper.IsTerminal(lifecycleStatus);
|
||
|
||
public static string? GetDayGroup(DateTime? scheduledDate)
|
||
{
|
||
if (!scheduledDate.HasValue)
|
||
return null;
|
||
|
||
return scheduledDate.Value.DayOfWeek switch
|
||
{
|
||
DayOfWeek.Monday => "monday",
|
||
DayOfWeek.Tuesday => "tuesday",
|
||
DayOfWeek.Wednesday => "wednesday",
|
||
DayOfWeek.Thursday => "thursday",
|
||
DayOfWeek.Friday => "friday",
|
||
_ => null
|
||
};
|
||
}
|
||
|
||
public static string? FormatApptTime(DateTime? start, DateTime? end)
|
||
{
|
||
if (!start.HasValue)
|
||
return null;
|
||
|
||
if (end.HasValue)
|
||
return $"{start.Value:HH:mm} – {end.Value:HH:mm}";
|
||
|
||
return start.Value.ToString("HH:mm");
|
||
}
|
||
|
||
public static string GetLifecycleStatusLabel(LifecycleStatus? status)
|
||
=> status.HasValue ? LifecycleStatusMapper.ToFeLabel(status.Value) : "";
|
||
}
|
||
}
|