diff --git a/EnvelopeGenerator.ServiceHost/Jobs/ActionService.cs b/EnvelopeGenerator.ServiceHost/Jobs/ActionService.cs index ea3165f6..336c2c5c 100644 --- a/EnvelopeGenerator.ServiceHost/Jobs/ActionService.cs +++ b/EnvelopeGenerator.ServiceHost/Jobs/ActionService.cs @@ -1,4 +1,6 @@ using DigitalData.Core.Abstraction.Application.Repository; +using EnvelopeGenerator.Application.Common.Dto; +using EnvelopeGenerator.Application.Common.Dto.Receiver; using EnvelopeGenerator.Domain.Entities; namespace EnvelopeGenerator.ServiceHost.Jobs; @@ -10,25 +12,25 @@ namespace EnvelopeGenerator.ServiceHost.Jobs; public class ActionService(IRepository histRepo) { [Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")] - public bool CreateReport(Envelope envelope, CancellationToken cancel = default) + public bool CreateReport(EnvelopeDto envelope, CancellationToken cancel = default) { throw new NotImplementedException(); } [Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")] - public bool FinalizeEnvelope(Envelope envelope, CancellationToken cancel = default) + public bool FinalizeEnvelope(EnvelopeDto envelope, CancellationToken cancel = default) { throw new NotImplementedException(); } [Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")] - public bool CompleteEnvelope(Envelope envelope, CancellationToken cancel = default) + public bool CompleteEnvelope(EnvelopeDto envelope, CancellationToken cancel = default) { throw new NotImplementedException(); } [Obsolete("This is a placeholder service added by copilot. Migrate the actual logic from CommonServices.Jobs")] - public bool CompleteEnvelope(Envelope envelope, Receiver receiver, CancellationToken cancel = default) + public bool CompleteEnvelope(EnvelopeDto envelope, ReceiverDto receiver, CancellationToken cancel = default) { throw new NotImplementedException(); } diff --git a/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs b/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs index 4939f62e..591ce5a4 100644 --- a/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs +++ b/EnvelopeGenerator.ServiceHost/Jobs/FinalizeDocumentJob.cs @@ -1,6 +1,7 @@ using DigitalData.Core.Abstraction.Application.Repository; using EnvelopeGenerator.Application.Common.Dto; using EnvelopeGenerator.Application.Configuration.Queries; +using EnvelopeGenerator.Application.Envelopes.Queries; using EnvelopeGenerator.Domain.Constants; using EnvelopeGenerator.Domain.Entities; using EnvelopeGenerator.ServiceHost.Exceptions; @@ -35,7 +36,7 @@ public class FinalizeDocumentJob(IOptions options, ILogger envelopes, CancellationToken cancel = default) { var gdPictureKey = _options.GdPictureLicenseKey; tempFiles.Create(); @@ -43,16 +44,6 @@ public class FinalizeDocumentJob(IOptions options, ILogger e.Status == EnvelopeStatus.EnvelopeCompletelySigned - && e.ChangedWhen.HasValue - && EF.Functions.DateDiffMinute(e.ChangedWhen.Value, DateTime.Now) >= CompleteWaitTime) - .OrderBy(e => e.Id) - .ToListAsync(cancel); - - if (envelopes.Count > 0) - logger.LogInformation("Found [{count}] completed envelopes.", envelopes.Count); - foreach (var envelope in envelopes) { try @@ -61,20 +52,29 @@ public class FinalizeDocumentJob(IOptions options, ILogger s.EnvelopeId == envelope.Id).Select(s => s.Value).ToListAsync(cancel); - var burnedDocument = pdfBurner!.BurnAnnotsToPDF(envelope.DefaultDocument.ByteData!, annotations, envelope.Id) + var burnedDocument = pdfBurner!.BurnAnnotsToPDF(envelope.Documents?.FirstOrDefault()?.ByteData!, annotations, envelope.Id) ?? throw new ApplicationException("Document could not be finalized"); actionService.CreateReport(envelope, cancel); @@ -104,10 +104,10 @@ public class FinalizeDocumentJob(IOptions options, ILogger options, ILogger options, ILogger()) + foreach (var receiver in envelope.EnvelopeReceivers ?? []) { - if (actionService?.CompleteEnvelope(envelope, receiver.Receiver) == false) - { - logger?.LogError(new Exception("CompleteEnvelope failed"), "Envelope could not be completed for receiver [{email}]", receiver.Receiver?.EmailAddress); + if (!actionService.CompleteEnvelope(envelope, receiver.Receiver!)) return false; - } } return true;