mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-04 16:02:11 +00:00
fix(work-orders): make stacked tip build for CI quality gates
This commit is contained in:
parent
62572d8e03
commit
fa1eca8f89
5 changed files with 111 additions and 9 deletions
|
|
@ -59,7 +59,11 @@ public class WorkOrderControllerSearchTests
|
||||||
Mock.Of<IWorkOrderBoardUpdateService>(),
|
Mock.Of<IWorkOrderBoardUpdateService>(),
|
||||||
Mock.Of<IWorkOrderBoardCreateService>(),
|
Mock.Of<IWorkOrderBoardCreateService>(),
|
||||||
Mock.Of<IWorkOrderBoardCancelService>(),
|
Mock.Of<IWorkOrderBoardCancelService>(),
|
||||||
advancedSearch);
|
advancedSearch,
|
||||||
|
Mock.Of<IWorkOrderDetailService>(),
|
||||||
|
Mock.Of<IWorkOrderCommentService>(),
|
||||||
|
Mock.Of<IWorkOrderCompletionService>(),
|
||||||
|
Mock.Of<IWorkOrderMediaService>());
|
||||||
|
|
||||||
controller.ControllerContext = new ControllerContext
|
controller.ControllerContext = new ControllerContext
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -33,5 +33,27 @@ namespace SeaHaven.DataServices.Implementation
|
||||||
{
|
{
|
||||||
return await _context.Users.AnyAsync(u => u.Id == id);
|
return await _context.Users.AnyAsync(u => u.Id == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IReadOnlyDictionary<string, string>> GetDisplayNamesByIdsAsync(IEnumerable<string> ids)
|
||||||
|
{
|
||||||
|
var idList = ids
|
||||||
|
.Where(id => !string.IsNullOrWhiteSpace(id))
|
||||||
|
.Distinct(StringComparer.Ordinal)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (idList.Count == 0)
|
||||||
|
return new Dictionary<string, string>(StringComparer.Ordinal);
|
||||||
|
|
||||||
|
var users = await _context.Users
|
||||||
|
.AsNoTracking()
|
||||||
|
.Where(u => idList.Contains(u.Id))
|
||||||
|
.Select(u => new { u.Id, u.FirstName, u.LastName })
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return users.ToDictionary(
|
||||||
|
u => u.Id,
|
||||||
|
u => $"{u.FirstName ?? ""} {u.LastName ?? ""}".Trim(),
|
||||||
|
StringComparer.Ordinal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,6 @@ namespace SeaHaven.DataServices.Interfaces
|
||||||
Task<IEnumerable<ApplicationUser>> GetAllAsync();
|
Task<IEnumerable<ApplicationUser>> GetAllAsync();
|
||||||
Task<ApplicationUser?> GetByEmailAsync(string email);
|
Task<ApplicationUser?> GetByEmailAsync(string email);
|
||||||
Task<bool> ExistsAsync(string id);
|
Task<bool> ExistsAsync(string id);
|
||||||
|
Task<IReadOnlyDictionary<string, string>> GetDisplayNamesByIdsAsync(IEnumerable<string> ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,23 +5,69 @@ namespace SeaHaven.Services.Helpers
|
||||||
{
|
{
|
||||||
public static class WorkOrderAuditProjection
|
public static class WorkOrderAuditProjection
|
||||||
{
|
{
|
||||||
public static WorkOrderAuditEntryDto ToDto(WorkOrderAuditLog log)
|
private const string UnassignedLabel = "Unassigned";
|
||||||
|
|
||||||
|
public static WorkOrderAuditEntryDto ToDto(
|
||||||
|
WorkOrderAuditLog log,
|
||||||
|
IReadOnlyDictionary<string, string>? assignToDisplayNames = null)
|
||||||
{
|
{
|
||||||
|
var oldValue = log.OldValue ?? "";
|
||||||
|
var newValue = log.NewValue ?? "";
|
||||||
|
|
||||||
|
if (IsAssignToField(log.FieldName))
|
||||||
|
{
|
||||||
|
oldValue = ResolveAssignToDisplay(oldValue, assignToDisplayNames);
|
||||||
|
newValue = ResolveAssignToDisplay(newValue, assignToDisplayNames);
|
||||||
|
}
|
||||||
|
|
||||||
return new WorkOrderAuditEntryDto
|
return new WorkOrderAuditEntryDto
|
||||||
{
|
{
|
||||||
Type = MapEventType(log.EventType),
|
Type = MapEventType(log.EventType),
|
||||||
DispatcherId = log.UserId,
|
DispatcherId = log.UserId,
|
||||||
Action = log.Action ?? "",
|
Action = log.Action ?? "",
|
||||||
FieldName = log.FieldName,
|
FieldName = log.FieldName,
|
||||||
OldValue = log.OldValue ?? "",
|
OldValue = oldValue,
|
||||||
NewValue = log.NewValue ?? "",
|
NewValue = newValue,
|
||||||
Time = log.CreatedAt.ToString("o"),
|
Time = log.CreatedAt.ToString("o"),
|
||||||
DispatchId = log.DispatchId
|
DispatchId = log.DispatchId
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<WorkOrderAuditEntryDto> ToDtos(IEnumerable<WorkOrderAuditLog> logs)
|
public static List<WorkOrderAuditEntryDto> ToDtos(
|
||||||
=> logs.Select(ToDto).ToList();
|
IEnumerable<WorkOrderAuditLog> logs,
|
||||||
|
IReadOnlyDictionary<string, string>? assignToDisplayNames = null)
|
||||||
|
=> logs.Select(log => ToDto(log, assignToDisplayNames)).ToList();
|
||||||
|
|
||||||
|
public static IEnumerable<string> CollectAssignToUserIds(IEnumerable<WorkOrderAuditLog> logs)
|
||||||
|
{
|
||||||
|
return logs
|
||||||
|
.Where(l => IsAssignToField(l.FieldName))
|
||||||
|
.SelectMany(l => new[] { l.OldValue, l.NewValue })
|
||||||
|
.Where(v => !string.IsNullOrWhiteSpace(v))
|
||||||
|
.Select(v => v!)
|
||||||
|
.Distinct(StringComparer.Ordinal);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static bool IsAssignToField(string? fieldName)
|
||||||
|
=> string.Equals(fieldName, "AssignTo", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| string.Equals(fieldName, "AssignedTo", StringComparison.OrdinalIgnoreCase);
|
||||||
|
|
||||||
|
private static string ResolveAssignToDisplay(
|
||||||
|
string value,
|
||||||
|
IReadOnlyDictionary<string, string>? assignToDisplayNames)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(value))
|
||||||
|
return UnassignedLabel;
|
||||||
|
|
||||||
|
if (assignToDisplayNames != null
|
||||||
|
&& assignToDisplayNames.TryGetValue(value, out var name)
|
||||||
|
&& !string.IsNullOrWhiteSpace(name))
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
private static string MapEventType(string? eventType)
|
private static string MapEventType(string? eventType)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,19 +5,48 @@ namespace SeaHaven.Services.Helpers
|
||||||
{
|
{
|
||||||
public static class WorkOrderCommentProjection
|
public static class WorkOrderCommentProjection
|
||||||
{
|
{
|
||||||
public static WorkOrderCommentDto ToDto(Comments comment)
|
public static WorkOrderCommentDto ToDto(
|
||||||
|
Comments comment,
|
||||||
|
IReadOnlyDictionary<string, string>? displayNames = null)
|
||||||
{
|
{
|
||||||
return new WorkOrderCommentDto
|
return new WorkOrderCommentDto
|
||||||
{
|
{
|
||||||
Id = comment.Id,
|
Id = comment.Id,
|
||||||
AuthorId = comment.UserId,
|
AuthorId = comment.UserId,
|
||||||
|
AuthorName = ResolveAuthorName(comment, displayNames),
|
||||||
Text = comment.Commenttext ?? "",
|
Text = comment.Commenttext ?? "",
|
||||||
Time = (comment.CreatedDate ?? DateTime.UtcNow).ToUniversalTime().ToString("o"),
|
Time = (comment.CreatedDate ?? DateTime.UtcNow).ToUniversalTime().ToString("o"),
|
||||||
Documents = comment.Documents
|
Documents = comment.Documents
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<WorkOrderCommentDto> ToDtos(IEnumerable<Comments> comments)
|
public static List<WorkOrderCommentDto> ToDtos(
|
||||||
=> comments.Select(ToDto).ToList();
|
IEnumerable<Comments> comments,
|
||||||
|
IReadOnlyDictionary<string, string>? displayNames = null)
|
||||||
|
=> comments.Select(c => ToDto(c, displayNames)).ToList();
|
||||||
|
|
||||||
|
public static IEnumerable<string> CollectAuthorUserIds(IEnumerable<Comments> comments)
|
||||||
|
=> comments
|
||||||
|
.Where(c => !string.IsNullOrWhiteSpace(c.UserId))
|
||||||
|
.Select(c => c.UserId!)
|
||||||
|
.Distinct(StringComparer.Ordinal);
|
||||||
|
|
||||||
|
private static string? ResolveAuthorName(
|
||||||
|
Comments comment,
|
||||||
|
IReadOnlyDictionary<string, string>? displayNames)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(comment.UserId)
|
||||||
|
&& displayNames != null
|
||||||
|
&& displayNames.TryGetValue(comment.UserId, out var name)
|
||||||
|
&& !string.IsNullOrWhiteSpace(name))
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(comment.Commenter))
|
||||||
|
return comment.Commenter.Trim();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue