shoc-backend/SeaHaven.DataServices/Implementation/WorkOrderOpsHealthDataService.cs

33 lines
1.2 KiB
C#
Raw Normal View History

2026-07-24 16:36:48 -03:00
using Data.SeaHavenIndustries;
using Microsoft.EntityFrameworkCore;
using SeaHaven.DataServices.Interfaces;
namespace SeaHaven.DataServices.Implementation
{
public class WorkOrderOpsHealthDataService : IWorkOrderOpsHealthDataService
{
private readonly ApplicationDbContext _context;
public WorkOrderOpsHealthDataService(ApplicationDbContext context)
{
_context = context;
}
public Task<int> CountSyncRejectedSinceAsync(DateTime since, CancellationToken cancellationToken)
=> _context.WorkOrderAuditLogs
.CountAsync(l => l.Action == "SyncRejected" && l.CreatedAt >= since, cancellationToken);
public Task<int> CountFieldLocksAsync(CancellationToken cancellationToken)
=> _context.WorkOrderFieldLocks.CountAsync(cancellationToken);
public async Task<DateTime?> GetLastWeekRolledProcessedAtAsync(CancellationToken cancellationToken)
{
if (!await _context.WorkOrderWeekRolledLedgers.AnyAsync(cancellationToken))
return null;
return await _context.WorkOrderWeekRolledLedgers
.MaxAsync(l => (DateTime?)l.ProcessedAt, cancellationToken);
}
}
}