mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 10:43:13 +00:00
Expose workorders/{id}/uplifts list/create/cancel/revoke for the SH-196 dialog, aggregate upliftSummary on board rows, and add service/controller regression tests.
100 lines
3.6 KiB
C#
100 lines
3.6 KiB
C#
using Data.SeaHavenIndustries;
|
|
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.RequestedNTE,
|
|
Notes = row.VendorReason ?? "",
|
|
RequestedAt = row.CreatedDate,
|
|
RequestedById = row.CreatedByUserId,
|
|
RequestedByName = row.RequestedByVendorName ?? "",
|
|
DecidedAt = row.DecidedAt,
|
|
DecidedByName = decidedByName,
|
|
DecisionNote = row.DecisionNote ?? "",
|
|
};
|
|
}
|
|
|
|
public static WorkOrderUpliftDto MapItem(DispatchUpliftRequest request, string? requestedByName, string? decidedByName)
|
|
=> new()
|
|
{
|
|
Id = request.Id,
|
|
Status = ToFrontendStatus(request.Status),
|
|
Amount = request.RequestedNTE,
|
|
Notes = request.VendorReason ?? "",
|
|
RequestedAt = request.CreatedDate,
|
|
RequestedById = request.createdby,
|
|
RequestedByName = requestedByName ?? request.RequestedByVendorName ?? "",
|
|
DecidedAt = request.DecidedAt,
|
|
DecidedByName = decidedByName ?? "",
|
|
DecisionNote = request.DecisionNote ?? "",
|
|
};
|
|
|
|
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();
|
|
}
|
|
}
|