refactor: simplify email sending logic and remove debug checks

- Removed unused `EnvelopeGenerator.Domain.Entities` import.
- Changed `SendFinalEmailWithAttachment` calls to explicitly cast envelope email type to `int`.
- Removed `Debug` conditional checks around history creation; history commands are now always sent.
- Made `SendFinalEmailWithAttachment` a static method for clarity.
This commit is contained in:
tekh 2025-11-12 15:44:37 +01:00
parent d442ad0ce0
commit fac5419589

View File

@ -1,6 +1,5 @@
using EnvelopeGenerator.Application.Histories.Commands;
using EnvelopeGenerator.Domain.Constants;
using EnvelopeGenerator.Domain.Entities;
using MediatR;
using Microsoft.Extensions.Logging;
@ -67,7 +66,7 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
private async Task SendFinalEmailToCreatorAsync(BurnPdfCommand request, CancellationToken cancel) //, string pAttachment
{
bool oIncludeAttachment = SendFinalEmailWithAttachment(request.Envelope!.FinalEmailToCreator);
bool oIncludeAttachment = SendFinalEmailWithAttachment((int)request.Envelope!.FinalEmailToCreator!);
// string oAttachment = string.Empty;
_logger.LogDebug("Attachment included: [{oIncludeAttachment}]", oIncludeAttachment);
@ -76,7 +75,6 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
// oAttachment = pAttachment;
}
if (!request.Debug)
await _sender.Send(new CreateHistoryCommand()
{
EnvelopeId = request.Envelope!.Id,
@ -87,7 +85,7 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
private async Task SendFinalEmailToReceiversAsync(BurnPdfCommand request, CancellationToken cancel) //, string pAttachment
{
bool oIncludeAttachment = SendFinalEmailWithAttachment(request.Envelope!.FinalEmailToReceivers);
bool oIncludeAttachment = SendFinalEmailWithAttachment((int)request.Envelope!.FinalEmailToReceivers!);
// string oAttachment = string.Empty;
_logger.LogDebug("Attachment included: [{oIncludeAttachment}]", oIncludeAttachment);
@ -97,7 +95,6 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
}
// TODO update CreateHistoryCommand to be able to create all records together
if (!request.Debug)
await Task.WhenAll(request.Envelope!.EnvelopeReceivers!.Select(receiver => _sender.Send(new CreateHistoryCommand()
{
EnvelopeId = request.Envelope!.Id,
@ -105,4 +102,6 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
UserReference = receiver.Receiver!.EmailAddress,
}, cancel)));
}
private static bool SendFinalEmailWithAttachment(int type) => type == (int)FinalEmailType.YesWithAttachment;
}