feat(uplifts): expose approval queue contract fields (SH-208)

This commit is contained in:
Alexandre Brandizzi 2026-09-16 22:32:23 -03:00
parent 60e006e8d7
commit e0e45d5ed3
5 changed files with 38 additions and 3 deletions

View file

@ -88,6 +88,8 @@ namespace Data.SeaHavenIndustries
public string? RequestedByVendorName { get; set; }
public string? RequestedByFirstName { get; set; }
public string? RequestedByLastName { get; set; }
public string? DecidedByFirstName { get; set; }
public string? DecidedByLastName { get; set; }
public decimal? CurrentNTE { get; set; }
public decimal RequestedNTE { get; set; }
public string? VendorReason { get; set; }
@ -104,6 +106,8 @@ namespace Data.SeaHavenIndustries
public DateTime? ExpiresAt { get; set; }
public string? NotificationStatus { get; set; }
public string? NotificationError { get; set; }
public int AttachmentCount { get; set; }
public bool WorkOrderClosed { get; set; }
}
public class UpliftForWorkOrderData : UpliftForDispatchData

View file

@ -1,5 +1,6 @@
using System.Collections.Concurrent;
using Data.SeaHavenIndustries;
using Data.SeaHavenIndustries.Enums;
using Microsoft.EntityFrameworkCore;
using SeaHaven.DataServices.Interfaces;
@ -28,9 +29,11 @@ namespace SeaHaven.DataServices.Implementation
from wo in workOrders.DefaultIfEmpty()
join reqUser in _context.Users on u.createdby equals reqUser.Id into requestUsers
from reqUser in requestUsers.DefaultIfEmpty()
join decUser in _context.Users on u.DecidedByUserId equals decUser.Id into decisionUsers
from decUser in decisionUsers.DefaultIfEmpty()
where (u.IsDeleted == null || u.IsDeleted == false)
&& (d.IsDeleted == null || d.IsDeleted == false)
select new { u, d, v, ev, wo, reqUser };
select new { u, d, v, ev, wo, reqUser, decUser };
if (!string.IsNullOrWhiteSpace(status))
query = query.Where(x => x.u.Status == status);
@ -67,6 +70,8 @@ namespace SeaHaven.DataServices.Implementation
RequestedByVendorName = x.u.RequestedByVendorName,
RequestedByFirstName = x.reqUser != null ? x.reqUser.FirstName : null,
RequestedByLastName = x.reqUser != null ? x.reqUser.LastName : null,
DecidedByFirstName = x.decUser != null ? x.decUser.FirstName : null,
DecidedByLastName = x.decUser != null ? x.decUser.LastName : null,
CurrentNTE = x.u.CurrentNTE,
RequestedNTE = x.u.RequestedNTE,
VendorReason = x.u.VendorReason,
@ -81,13 +86,29 @@ namespace SeaHaven.DataServices.Implementation
EvidenceSizeBytes = x.ev != null ? x.ev.SizeBytes : null,
ExpiresAt = x.u.ExpiresAt,
NotificationStatus = x.u.NotificationStatus,
NotificationError = x.u.NotificationError
NotificationError = x.u.NotificationError,
AttachmentCount = _context.VendorCompletionDocuments.Count(document =>
document.DispatchId == x.d.Id
&& (document.IsDeleted == null || document.IsDeleted == false)),
WorkOrderClosed = x.wo != null
&& (x.wo.LifecycleStatus == LifecycleStatus.Completed
|| x.wo.LifecycleStatus == LifecycleStatus.Canceled)
})
.ToListAsync(cancellationToken);
return (total, items);
}
public Task<decimal> GetPendingExposureAsync(CancellationToken cancellationToken)
{
return _context.DispatchUpliftRequests
.Where(u => (u.IsDeleted == null || u.IsDeleted == false)
&& u.Status == "Pending")
.SumAsync(u => u.createdby == null
? u.RequestedNTE - (u.CurrentNTE ?? 0m)
: u.RequestedNTE, cancellationToken);
}
public async Task<IReadOnlyList<UpliftForDispatchData>> GetForDispatchAsync(int dispatchId, CancellationToken cancellationToken)
{
return await (from u in _context.DispatchUpliftRequests

View file

@ -6,6 +6,7 @@ namespace SeaHaven.DataServices.Interfaces
{
Task<(int TotalCount, IReadOnlyList<UpliftListItemData> Items)> GetPagedAsync(
string? status, int? tier, int page, int pageSize, CancellationToken cancellationToken);
Task<decimal> GetPendingExposureAsync(CancellationToken cancellationToken);
Task<IReadOnlyList<UpliftForDispatchData>> GetForDispatchAsync(int dispatchId, CancellationToken cancellationToken);
Task<IReadOnlyList<UpliftForWorkOrderData>> GetForWorkOrderAsync(int workOrderId, CancellationToken cancellationToken);
Task<DispatchUpliftRequest?> GetByIdAndWorkOrderAsync(int requestId, int workOrderId, CancellationToken cancellationToken);

View file

@ -13,6 +13,7 @@ namespace SeaHaven.Services.DTOs
public string? WorkOrderSite { get; set; }
public string? WorkOrderService { get; set; }
public string? RequestedByName { get; set; }
public string? DecidedByName { get; set; }
public decimal? CurrentNTE { get; set; }
public decimal RequestedNTE { get; set; }
public decimal Delta { get; set; }
@ -31,6 +32,8 @@ namespace SeaHaven.Services.DTOs
public DateTime? ExpiresAt { get; set; }
public string? NotificationStatus { get; set; }
public string? NotificationError { get; set; }
public int AttachmentCount { get; set; }
public bool WorkOrderClosed { get; set; }
// Approved-on-WO exposure totals for this item's work order: auto-approved and
// admin-approved amounts; pending, rejected, cancelled/withdrawn, and revoked
// requests are excluded.
@ -44,6 +47,7 @@ namespace SeaHaven.Services.DTOs
public int Total { get; set; }
public int Page { get; set; }
public int PageSize { get; set; }
public decimal PendingExposureTotal { get; set; }
public IEnumerable<UpliftListItemDTO> Items { get; set; } = Enumerable.Empty<UpliftListItemDTO>();
}

View file

@ -33,6 +33,7 @@ namespace SeaHaven.Services.Implementation
public async Task<UpliftListResultDTO> ListAsync(ClaimsPrincipal user, string? status, int? tier, int page, int pageSize, CancellationToken cancellationToken)
{
var (total, items) = await _upliftData.GetPagedAsync(status, tier, page, pageSize, cancellationToken);
var pendingExposureTotal = await _upliftData.GetPendingExposureAsync(cancellationToken);
var mapped = items.Select(r => new UpliftListItemDTO
{
@ -46,6 +47,7 @@ namespace SeaHaven.Services.Implementation
WorkOrderSite = r.WorkOrderSiteCode,
WorkOrderService = r.WorkOrderService,
RequestedByName = ResolveRequestedByName(r.RequestedByVendorName, r.RequestedByFirstName, r.RequestedByLastName),
DecidedByName = ResolveRequestedByName(null, r.DecidedByFirstName, r.DecidedByLastName),
CurrentNTE = r.CurrentNTE,
RequestedNTE = r.RequestedNTE,
Delta = r.RequestedNTE - (r.CurrentNTE ?? 0m),
@ -62,7 +64,9 @@ namespace SeaHaven.Services.Implementation
EvidenceSizeBytes = r.EvidenceSizeBytes,
ExpiresAt = r.ExpiresAt,
NotificationStatus = r.NotificationStatus,
NotificationError = r.NotificationError
NotificationError = r.NotificationError,
AttachmentCount = r.AttachmentCount,
WorkOrderClosed = r.WorkOrderClosed
}).ToList();
// Approved-on-WO exposure totals are aggregated once for the whole page
@ -90,6 +94,7 @@ namespace SeaHaven.Services.Implementation
Total = total,
Page = page,
PageSize = pageSize,
PendingExposureTotal = pendingExposureTotal,
Items = mapped
};
}