fix(work-orders): never return a severity on an Overdue board row

A standalone severity patch on an Overdue WO still stores the value,
because the board patches severity before type when correcting Overdue
to Emergency/Reactive and that write must not be dropped or rejected.
Project the severity as null for Overdue in the board row mapping, which
also feeds the PATCH response, search results and the detail view, so a
stored value never surfaces on a type that carries no severity.
This commit is contained in:
Alexandre Brandizzi 2026-09-25 13:41:19 -03:00
parent c1910e5310
commit 47060f6a73
2 changed files with 35 additions and 2 deletions

View file

@ -147,7 +147,12 @@ namespace SeaHaven.Services.Implementation
MediaCount = row.MediaCount,
CompletedDate = row.CompletedDate,
FlagColor = row.FlagColor,
Severity = WorkOrderSeverityRules.ParseLevel(row.Severity),
// Overdue never carries a severity. A standalone severity patch can still
// store one (the board patches severity before type when correcting Overdue
// to Emergency/Reactive), so the row never returns it for an Overdue WO.
Severity = row.WorkOrderType == WorkOrderType.Overdue
? null
: WorkOrderSeverityRules.ParseLevel(row.Severity),
PrimaryDispatchId = row.PrimaryDispatchId,
RowVersion = row.RowVersion,
DispatchRowVersion = row.DispatchRowVersion,

View file

@ -202,12 +202,13 @@ public class WorkOrderOverdueTypeTests
await context.SaveChangesAsync();
var service = NewUpdateService(context);
await service.PatchFieldAsync(1, new WorkOrderBoardPatchRequestDto
var severityStep = await service.PatchFieldAsync(1, new WorkOrderBoardPatchRequestDto
{
Field = WorkOrderBoardFieldNames.Severity,
Value = "2",
WorkOrderVersion = ToVersion(wo)
}, "actor-1");
Assert.Null(severityStep.Severity);
var updated = await context.workOrders.SingleAsync(w => w.Id == 1);
var result = await service.PatchFieldAsync(1, new WorkOrderBoardPatchRequestDto
@ -224,6 +225,33 @@ public class WorkOrderOverdueTypeTests
Assert.Equal("2", persisted.Severity);
}
// A severity patch with no following type change leaves a stored value on an
// Overdue WO; the board row still reports no severity.
[Fact]
public async Task PatchSeverity_OnOverdue_RowShowsNoSeverity()
{
await using var context = NewContext();
var wo = new WorkOrder
{
Id = 1,
LifecycleStatus = LifecycleStatus.Scheduled,
WorkOrderType = WorkOrderType.Overdue,
RowVersion = new byte[] { 1, 0, 0, 0, 0, 0, 0, 1 }
};
context.workOrders.Add(wo);
await context.SaveChangesAsync();
var result = await NewUpdateService(context).PatchFieldAsync(1, new WorkOrderBoardPatchRequestDto
{
Field = WorkOrderBoardFieldNames.Severity,
Value = "3",
WorkOrderVersion = ToVersion(wo)
}, "actor-1");
Assert.Equal(WorkOrderType.Overdue, result.WorkOrderType);
Assert.Null(result.Severity);
}
[Fact]
public async Task PatchType_PmWithPmService_ToOverdue_KeepsService()
{