shoc-backend/SeaHaven.Services/Helpers/WorkOrderUpliftContractMapper.cs
Arthur Bassi 31dd2d5dcd merge(main): keep uplift evidence on the current work-order routes
The route contract keeps the poc endpoint from main and the uplift evidence routes from this branch. Create still passes the scanned evidence document through the locked mutation.
2026-09-28 15:56:45 -03:00

104 lines
3.9 KiB
C#

using Data.SeaHavenIndustries;
using SeaHaven.DataServices.Helpers;
using SeaHaven.DataServices.Interfaces;
using SeaHaven.Services.DTOs;
using SeaHaven.Services.Implementation;
namespace SeaHaven.Services.Helpers
{
public static class WorkOrderUpliftContractMapper
{
public static WorkOrderUpliftSummaryDto MapSummary(
bool hasUplift,
int pendingCount,
string? primaryStatus,
decimal? amount)
{
var summary = new WorkOrderUpliftSummaryDto
{
HasUplift = hasUplift || pendingCount > 0,
PendingCount = pendingCount,
};
if (!string.IsNullOrWhiteSpace(primaryStatus))
{
summary.PrimaryStatus = ToFrontendStatus(primaryStatus);
}
if (amount.HasValue)
{
summary.Amount = amount.Value;
}
return summary;
}
public static WorkOrderUpliftSummaryDto MapSummary(WorkOrderBoardRawRow row)
=> MapSummary(row.HasUplift, row.PendingUpliftCount, row.PrimaryUpliftStatus, row.PrimaryUpliftAmount);
public static WorkOrderUpliftDto MapItem(UpliftForWorkOrderData row)
{
var decidedByName = FormatName(row.DecidedByFirstName, row.DecidedByLastName);
return new WorkOrderUpliftDto
{
Id = row.Id,
Status = ToFrontendStatus(row.Status),
Amount = row.Amount,
Notes = row.VendorReason ?? "",
RequestedAt = row.CreatedDate,
RequestedById = row.CreatedByUserId,
RequestedByName = row.RequestedByVendorName ?? "",
DecidedAt = row.DecidedAt,
DecidedByName = decidedByName,
DecisionNote = row.DecisionNote ?? "",
EvidenceDocumentId = row.EvidenceDocumentId,
EvidenceFileName = row.EvidenceFileName ?? "",
};
}
public static WorkOrderUpliftDto MapItem(DispatchUpliftRequest request, string? requestedByName, string? decidedByName)
=> new()
{
Id = request.Id,
Status = ToFrontendStatus(request.Status),
Amount = UpliftAmount.Of(request),
Notes = request.VendorReason ?? "",
RequestedAt = request.CreatedDate,
RequestedById = request.createdby,
RequestedByName = requestedByName ?? request.RequestedByVendorName ?? "",
DecidedAt = request.DecidedAt,
DecidedByName = decidedByName ?? "",
DecisionNote = request.DecisionNote ?? "",
EvidenceDocumentId = request.EvidenceDocumentId,
};
public static WorkOrderUpliftDto MapRevokedItem(
DispatchUpliftRequest request,
string? requestedByName,
string decidedByName)
{
var dto = MapItem(request, requestedByName, decidedByName);
dto.Status = "revoked";
return dto;
}
public static string ToFrontendStatus(string? backendStatus)
{
return UpliftStatus.ToCanonical(backendStatus) switch
{
UpliftStatus.Pending => "pending",
UpliftStatus.Approved => "approved",
UpliftStatus.NoApprovalRequired => "auto_approved",
UpliftStatus.Rejected => "rejected",
UpliftStatus.Withdrawn => "cancelled",
UpliftStatus.Revoked => "revoked",
UpliftStatus.ChangesRequested => "pending",
UpliftStatus.Expired => "cancelled",
_ => "pending",
};
}
private static string FormatName(string? firstName, string? lastName)
=> $"{firstName ?? ""} {lastName ?? ""}".Trim();
}
}