diff --git a/src/api/SIGCM2.Infrastructure/Audit/AuditLogger.cs b/src/api/SIGCM2.Infrastructure/Audit/AuditLogger.cs index 6376ec1..4794726 100644 --- a/src/api/SIGCM2.Infrastructure/Audit/AuditLogger.cs +++ b/src/api/SIGCM2.Infrastructure/Audit/AuditLogger.cs @@ -12,15 +12,18 @@ public sealed class AuditLogger : IAuditLogger private readonly IAuditContext _context; private readonly IAuditEventRepository _repo; private readonly IOptions _options; + private readonly TimeProvider _timeProvider; public AuditLogger( IAuditContext context, IAuditEventRepository repo, - IOptions options) + IOptions options, + TimeProvider timeProvider) { _context = context; _repo = repo; _options = options; + _timeProvider = timeProvider; } public async Task LogAsync( @@ -42,7 +45,7 @@ public sealed class AuditLogger : IAuditLogger : _context.CorrelationId; await _repo.InsertAsync( - occurredAt: DateTime.UtcNow, + occurredAt: _timeProvider.GetUtcNow().UtcDateTime, actorUserId: _context.ActorUserId, actorRoleId: _context.ActorRoleId, action: action, diff --git a/src/api/SIGCM2.Infrastructure/Audit/SecurityEventLogger.cs b/src/api/SIGCM2.Infrastructure/Audit/SecurityEventLogger.cs index 3b3a94e..b3398ca 100644 --- a/src/api/SIGCM2.Infrastructure/Audit/SecurityEventLogger.cs +++ b/src/api/SIGCM2.Infrastructure/Audit/SecurityEventLogger.cs @@ -11,15 +11,18 @@ public sealed class SecurityEventLogger : ISecurityEventLogger private readonly ISecurityEventRepository _repo; private readonly IAuditContext _context; private readonly IOptions _options; + private readonly TimeProvider _timeProvider; public SecurityEventLogger( ISecurityEventRepository repo, IAuditContext context, - IOptions options) + IOptions options, + TimeProvider timeProvider) { _repo = repo; _context = context; _options = options; + _timeProvider = timeProvider; } public async Task LogAsync( @@ -37,7 +40,7 @@ public sealed class SecurityEventLogger : ISecurityEventLogger : JsonSanitizer.Sanitize(metadata, _options.Value.SanitizedKeys); await _repo.InsertAsync( - occurredAt: DateTime.UtcNow, + occurredAt: _timeProvider.GetUtcNow().UtcDateTime, actorUserId: actorUserId, attemptedUsername: attemptedUsername, sessionId: sessionId, diff --git a/src/api/SIGCM2.Infrastructure/DependencyInjection.cs b/src/api/SIGCM2.Infrastructure/DependencyInjection.cs index a638f1f..0931998 100644 --- a/src/api/SIGCM2.Infrastructure/DependencyInjection.cs +++ b/src/api/SIGCM2.Infrastructure/DependencyInjection.cs @@ -68,7 +68,10 @@ public static class DependencyInjection }); services.AddScoped(sp => - new JwtService(sp.GetRequiredService(), sp.GetRequiredService())); + new JwtService( + sp.GetRequiredService(), + sp.GetRequiredService(), + sp.GetRequiredService())); services.AddScoped(); services.AddSingleton(); services.AddHttpContextAccessor(); diff --git a/src/api/SIGCM2.Infrastructure/Persistence/MedioRepository.cs b/src/api/SIGCM2.Infrastructure/Persistence/MedioRepository.cs index 99dc1ca..8c197ef 100644 --- a/src/api/SIGCM2.Infrastructure/Persistence/MedioRepository.cs +++ b/src/api/SIGCM2.Infrastructure/Persistence/MedioRepository.cs @@ -85,7 +85,7 @@ public sealed class MedioRepository : IMedioRepository Tipo = (int)m.Tipo, m.PlataformaEmpresaId, m.Activo, - FechaModificacion = m.FechaModificacion ?? DateTime.UtcNow, + FechaModificacion = m.FechaModificacion, m.Id, }); } diff --git a/src/api/SIGCM2.Infrastructure/Persistence/PuntoDeVentaRepository.cs b/src/api/SIGCM2.Infrastructure/Persistence/PuntoDeVentaRepository.cs index d276536..5749ead 100644 --- a/src/api/SIGCM2.Infrastructure/Persistence/PuntoDeVentaRepository.cs +++ b/src/api/SIGCM2.Infrastructure/Persistence/PuntoDeVentaRepository.cs @@ -96,7 +96,7 @@ public sealed class PuntoDeVentaRepository : IPuntoDeVentaRepository pdv.Nombre, pdv.Descripcion, pdv.Activo, - FechaModificacion = pdv.FechaModificacion ?? DateTime.UtcNow, + FechaModificacion = pdv.FechaModificacion, pdv.Id, }); } diff --git a/src/api/SIGCM2.Infrastructure/Persistence/SeccionRepository.cs b/src/api/SIGCM2.Infrastructure/Persistence/SeccionRepository.cs index 6ec75eb..327c7cc 100644 --- a/src/api/SIGCM2.Infrastructure/Persistence/SeccionRepository.cs +++ b/src/api/SIGCM2.Infrastructure/Persistence/SeccionRepository.cs @@ -84,7 +84,7 @@ public sealed class SeccionRepository : ISeccionRepository s.Nombre, s.Tipo, s.Activo, - FechaModificacion = s.FechaModificacion ?? DateTime.UtcNow, + FechaModificacion = s.FechaModificacion, s.Id, }); } diff --git a/src/api/SIGCM2.Infrastructure/Security/JwtService.cs b/src/api/SIGCM2.Infrastructure/Security/JwtService.cs index 85ab73e..e52c2a7 100644 --- a/src/api/SIGCM2.Infrastructure/Security/JwtService.cs +++ b/src/api/SIGCM2.Infrastructure/Security/JwtService.cs @@ -11,11 +11,13 @@ public sealed class JwtService : IJwtService { private readonly RSA _rsa; private readonly JwtOptions _options; + private readonly TimeProvider _timeProvider; - public JwtService(RSA rsa, JwtOptions options) + public JwtService(RSA rsa, JwtOptions options, TimeProvider timeProvider) { _rsa = rsa; _options = options; + _timeProvider = timeProvider; } /// @@ -62,7 +64,7 @@ public sealed class JwtService : IJwtService new("rol", usuario.Rol), }; - var now = DateTime.UtcNow; + var now = _timeProvider.GetUtcNow().UtcDateTime; var descriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(claims),