mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-01 23:13:22 +00:00
Auto-approved evidence was hidden because download checked the approval tier. Viewers of the work order can open it, and a request can store more than one scanned document.
107 lines
4 KiB
C#
107 lines
4 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 ?? "",
|
|
Attachments = row.Attachments
|
|
.Select(file => new WorkOrderUpliftAttachmentDto { Id = file.Id, Name = file.Name })
|
|
.ToList(),
|
|
};
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|