mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 14:13:12 +00:00
Adds an extra safety note and an ordered procedure list to completion document templates, name search, creator and last-updated audit fields, a tenant-scoped count of open work orders that depend on a template, and a delete that unlinks Services while they keep requiring a document. Writes are gated by the create/edit/delete completion template team permissions instead of the Admin role.
47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
using Data.SeaHavenIndustries;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using SeaHaven.DataServices.Helpers;
|
|
using SeaHaven.DataServices.Interfaces;
|
|
|
|
namespace SeaHaven.DataServices.Implementation
|
|
{
|
|
public class WorkOrderCompletionDataService : IWorkOrderCompletionDataService
|
|
{
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
public WorkOrderCompletionDataService(ApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public Task<WorkOrder?> GetWorkOrderForCompletionAuthAsync(
|
|
int workOrderId,
|
|
int? accountId,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var query = WorkOrderBoardQueryFilters.ApplyBaseScope(_context.workOrders.AsNoTracking());
|
|
if (accountId.HasValue)
|
|
query = WorkOrderBoardQueryFilters.ApplyAccountScope(query, accountId.Value);
|
|
|
|
return query.FirstOrDefaultAsync(w => w.Id == workOrderId, cancellationToken);
|
|
}
|
|
|
|
public Task<WorkOrder?> GetTrackedWorkOrderAsync(
|
|
int workOrderId,
|
|
int? accountId,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var query = WorkOrderBoardQueryFilters.ApplyBaseScope(_context.workOrders);
|
|
if (accountId.HasValue)
|
|
query = WorkOrderBoardQueryFilters.ApplyAccountScope(query, accountId.Value);
|
|
|
|
return query.FirstOrDefaultAsync(w => w.Id == workOrderId, cancellationToken);
|
|
}
|
|
|
|
public void SetExpectedWorkOrderVersion(WorkOrder workOrder, byte[] version)
|
|
=> _context.Entry(workOrder).Property(w => w.RowVersion).OriginalValue = version;
|
|
|
|
public Task SaveAsync(CancellationToken cancellationToken)
|
|
=> _context.SaveChangesAsync(cancellationToken);
|
|
}
|
|
}
|