mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-01 14:33:15 +00:00
41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using Data.SeaHavenIndustries;
|
|
using SeaHaven.Services.DTOs;
|
|
|
|
namespace SeaHaven.Services.Helpers
|
|
{
|
|
public static class WorkOrderAuditProjection
|
|
{
|
|
public static WorkOrderAuditEntryDto ToDto(WorkOrderAuditLog log)
|
|
{
|
|
return new WorkOrderAuditEntryDto
|
|
{
|
|
Type = MapEventType(log.EventType),
|
|
DispatcherId = log.UserId,
|
|
Action = log.Action ?? "",
|
|
FieldName = log.FieldName,
|
|
OldValue = log.OldValue ?? "",
|
|
NewValue = log.NewValue ?? "",
|
|
Time = log.CreatedAt.ToString("o"),
|
|
DispatchId = log.DispatchId
|
|
};
|
|
}
|
|
|
|
public static List<WorkOrderAuditEntryDto> ToDtos(IEnumerable<WorkOrderAuditLog> logs)
|
|
=> logs.Select(ToDto).ToList();
|
|
|
|
private static string MapEventType(string? eventType)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(eventType))
|
|
return "manual";
|
|
|
|
return eventType.ToLowerInvariant() switch
|
|
{
|
|
"manual" => "manual",
|
|
"system" => "system",
|
|
"sync" => "sync",
|
|
"vendor" => "vendor",
|
|
_ => eventType.ToLowerInvariant()
|
|
};
|
|
}
|
|
}
|
|
}
|