mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 21:13:12 +00:00
97 lines
2.8 KiB
C#
97 lines
2.8 KiB
C#
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace SeaHaven.Services.Helpers
|
|
{
|
|
public static class WorkOrderExternalVersion
|
|
{
|
|
public static string ComputeWorkOrder(WorkOrder value) => Compute(
|
|
value.WorkOrderId,
|
|
value.Status,
|
|
value.Description,
|
|
value.Customer,
|
|
value.SiteCode,
|
|
value.Building,
|
|
value.Address,
|
|
value.Severity,
|
|
value.Priority,
|
|
value.AssignedTo,
|
|
Format(value.DateReported),
|
|
Format(value.ScheduledStart),
|
|
Format(value.DueDate),
|
|
value.RecordType,
|
|
Format(value.CreatedAt),
|
|
value.SourceEmailS3Key,
|
|
null,
|
|
null,
|
|
null,
|
|
null);
|
|
|
|
public static string ComputeComment(Comment value) => Compute(
|
|
value.WorkOrderId,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
null,
|
|
value.RecordType,
|
|
Format(value.CreatedAt),
|
|
value.SourceEmailS3Key,
|
|
value.CommentId,
|
|
value.Commenter,
|
|
value.Text,
|
|
Format(value.IngestedAt));
|
|
|
|
public static string Compute(params string?[] values)
|
|
{
|
|
var buffer = new StringBuilder();
|
|
foreach (var value in values)
|
|
{
|
|
var normalized = value ?? string.Empty;
|
|
buffer.Append(normalized.Length).Append(':').Append(normalized).Append('|');
|
|
}
|
|
|
|
return Convert.ToHexString(
|
|
SHA256.HashData(Encoding.UTF8.GetBytes(buffer.ToString())))
|
|
.ToLowerInvariant();
|
|
}
|
|
|
|
private static string? Format(DateTimeOffset? value) =>
|
|
value?.ToUniversalTime().ToString("O");
|
|
|
|
public sealed record WorkOrder(
|
|
string WorkOrderId,
|
|
string? Status,
|
|
string? Description,
|
|
string? Customer,
|
|
string? SiteCode,
|
|
string? Building,
|
|
string? Address,
|
|
string? Severity,
|
|
string? Priority,
|
|
string? AssignedTo,
|
|
DateTimeOffset? DateReported,
|
|
DateTimeOffset? ScheduledStart,
|
|
DateTimeOffset? DueDate,
|
|
string? RecordType,
|
|
DateTimeOffset? CreatedAt,
|
|
string? SourceEmailS3Key);
|
|
|
|
public sealed record Comment(
|
|
string WorkOrderId,
|
|
string CommentId,
|
|
string? RecordType,
|
|
string? Commenter,
|
|
string? Text,
|
|
DateTimeOffset? CreatedAt,
|
|
DateTimeOffset? IngestedAt,
|
|
string? SourceEmailS3Key);
|
|
}
|
|
}
|