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