@@ -3,6 +3,8 @@ using Microsoft.EntityFrameworkCore;
|
||||
using ROLAC.API.Data;
|
||||
using ROLAC.API.DTOs.Expense;
|
||||
using ROLAC.API.Entities;
|
||||
using ROLAC.API.Entities.Logging;
|
||||
using ROLAC.API.Services.Logging;
|
||||
|
||||
namespace ROLAC.API.Services;
|
||||
|
||||
@@ -10,7 +12,9 @@ public class MonthlyStatementService : IMonthlyStatementService
|
||||
{
|
||||
private readonly AppDbContext _db;
|
||||
private readonly IHttpContextAccessor _http;
|
||||
public MonthlyStatementService(AppDbContext db, IHttpContextAccessor http) { _db = db; _http = http; }
|
||||
private readonly IAuditLogger _audit;
|
||||
public MonthlyStatementService(AppDbContext db, IHttpContextAccessor http, IAuditLogger audit)
|
||||
{ _db = db; _http = http; _audit = audit; }
|
||||
|
||||
// See ExpenseService: the user id lives in the "sub" claim at runtime; NameIdentifier is for tests.
|
||||
private string CurrentUserId =>
|
||||
@@ -66,6 +70,11 @@ public class MonthlyStatementService : IMonthlyStatementService
|
||||
?? throw new KeyNotFoundException($"MonthlyStatement {id} not found.");
|
||||
s.IsFinalized = true; s.FinalizedAt = DateTimeOffset.UtcNow; s.FinalizedBy = CurrentUserId;
|
||||
await _db.SaveChangesAsync();
|
||||
|
||||
_audit.Write(
|
||||
AuditActions.StatementFinalized, AuditCategories.Business, LogLevelEnum.Information,
|
||||
entityName: nameof(MonthlyStatement), entityId: s.Id.ToString(),
|
||||
summary: $"Monthly statement {s.Year}-{s.Month:D2} finalized");
|
||||
}
|
||||
|
||||
private async Task RecomputeAsync(MonthlyStatement s)
|
||||
|
||||
Reference in New Issue
Block a user