refactor(SendEmailBehavior): update to add history recors when request is not debug

This commit is contained in:
tekh 2025-11-12 15:35:23 +01:00
parent cbe2acc37d
commit d442ad0ce0

View File

@ -43,7 +43,7 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
if (mailToCreator is not null && mailToCreator != (int)FinalEmailType.No)
{
_logger.LogDebug("Sending email to creator ...");
await SendFinalEmailToCreatorAsync(request.Envelope, cancel); // , pAttachment
await SendFinalEmailToCreatorAsync(request, cancel); // , pAttachment
}
else
{
@ -54,7 +54,7 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
if (mailToReceivers != (int)FinalEmailType.No)
{
_logger.LogDebug("Sending emails to receivers...");
await SendFinalEmailToReceiversAsync(request.Envelope, cancel); // , pAttachment
await SendFinalEmailToReceiversAsync(request, cancel); // , pAttachment
}
else
{
@ -65,9 +65,9 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
return docResult;
}
private async Task SendFinalEmailToCreatorAsync(Envelope envelope, CancellationToken cancel) //, string pAttachment
private async Task SendFinalEmailToCreatorAsync(BurnPdfCommand request, CancellationToken cancel) //, string pAttachment
{
bool oIncludeAttachment = SendFinalEmailWithAttachment(envelope.FinalEmailToCreator);
bool oIncludeAttachment = SendFinalEmailWithAttachment(request.Envelope!.FinalEmailToCreator);
// string oAttachment = string.Empty;
_logger.LogDebug("Attachment included: [{oIncludeAttachment}]", oIncludeAttachment);
@ -76,17 +76,18 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
// oAttachment = pAttachment;
}
if (!request.Debug)
await _sender.Send(new CreateHistoryCommand()
{
EnvelopeId = envelope.Id,
EnvelopeId = request.Envelope!.Id,
Status = EnvelopeStatus.MessageCompletionSent,
UserReference = envelope.User.Email,
UserReference = request.Envelope.User.Email,
}, cancel);
}
private async Task SendFinalEmailToReceiversAsync(Envelope envelope, CancellationToken cancel) //, string pAttachment
private async Task SendFinalEmailToReceiversAsync(BurnPdfCommand request, CancellationToken cancel) //, string pAttachment
{
bool oIncludeAttachment = SendFinalEmailWithAttachment(envelope.FinalEmailToReceivers);
bool oIncludeAttachment = SendFinalEmailWithAttachment(request.Envelope!.FinalEmailToReceivers);
// string oAttachment = string.Empty;
_logger.LogDebug("Attachment included: [{oIncludeAttachment}]", oIncludeAttachment);
@ -96,9 +97,10 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
}
// TODO update CreateHistoryCommand to be able to create all records together
await Task.WhenAll(envelope.EnvelopeReceivers!.Select(receiver => _sender.Send(new CreateHistoryCommand()
if (!request.Debug)
await Task.WhenAll(request.Envelope!.EnvelopeReceivers!.Select(receiver => _sender.Send(new CreateHistoryCommand()
{
EnvelopeId = envelope.Id,
EnvelopeId = request.Envelope!.Id,
Status = EnvelopeStatus.MessageCompletionSent,
UserReference = receiver.Receiver!.EmailAddress,
}, cancel)));