Added logic to filter history records by receiver signature when provided in RemoveSignatureNotification. This ensures only relevant signed entries are deleted.
44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using EnvelopeGenerator.Application.Common.Extensions;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
using MediatR;
|
|
|
|
namespace EnvelopeGenerator.Application.Common.Notifications.RemoveSignature.Handlers;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public class RemoveHistoryHandler : INotificationHandler<RemoveSignatureNotification>
|
|
{
|
|
private readonly IRepository<Domain.Entities.History> _repo;
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="repository"></param>
|
|
public RemoveHistoryHandler(IRepository<Domain.Entities.History> repository)
|
|
{
|
|
_repo = repository;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="notification"></param>
|
|
/// <param name="cancel"></param>
|
|
/// <returns></returns>
|
|
public Task Handle(RemoveSignatureNotification notification, CancellationToken cancel)
|
|
{
|
|
return _repo.DeleteAsync(hists =>
|
|
{
|
|
hists = hists
|
|
.Where(hist => hist.Envelope!.Uuid == notification.EnvelopeUuid)
|
|
.Where(hist => hist.Status == EnvelopeStatus.DocumentSigned);
|
|
|
|
if (notification.ReceiverSignature is string signature)
|
|
hists = hists.Where(hist => hist.Receiver!.Signature == signature);
|
|
|
|
return hists;
|
|
}, cancel);
|
|
}
|
|
} |