Refactor envelope and receiver methods for clarity
- Changed return type of `CreateEnvelopeAsync` to ensure a non-null `Envelope` is always returned. - Updated `AddEnvelopeReceiverAsync` to allow nullable `salutation` parameter. - Renamed cancellation token parameter in `CreateEnvelopeReceiverCommandHandler` for consistency. - Enhanced error handling in `CreateEnvelopeAsync` to throw exceptions on failure with improved messages. - Adjusted `CreateParameters` method to accept nullable `salutation`.
This commit is contained in:
@@ -20,18 +20,19 @@ public class EnvelopeExecutor : SQLExecutor, IEnvelopeExecutor
|
||||
_envelopeRepository = envelopeRepository;
|
||||
}
|
||||
|
||||
public async Task<Envelope?> CreateEnvelopeAsync(int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default)
|
||||
public async Task<Envelope> CreateEnvelopeAsync(int userId, string title = "", string message = "", bool tfaEnabled = false, CancellationToken cancellation = default)
|
||||
{
|
||||
using var connection = new SqlConnection(Params.ConnectionString);
|
||||
var sql = Provider.GetRequiredService<EnvelopeCreateReadSQL>();
|
||||
await connection.OpenAsync(cancellation);
|
||||
var parameters = EnvelopeCreateReadSQL.CreateParmas(userId, title, message, tfaEnabled);
|
||||
var envelopes = await connection.QueryAsync<Envelope>(sql.Raw, parameters);
|
||||
var envelope = envelopes.FirstOrDefault();
|
||||
|
||||
if (envelope is null)
|
||||
return null;
|
||||
|
||||
return await _envelopeRepository.ReadByUuidAsync(envelope.Uuid, withAll: true);
|
||||
var envelope = envelopes.FirstOrDefault()
|
||||
?? throw new InvalidOperationException($"Envelope creation failed. Parameters:" +
|
||||
$"userId={userId}, title='{title}', message='{message}', tfaEnabled={tfaEnabled}."); ;
|
||||
|
||||
return await _envelopeRepository.ReadByUuidAsync(envelope.Uuid, withAll: true)
|
||||
?? throw new InvalidOperationException($"Envelope creation succeeded but retrieval failed. Parameters:" +
|
||||
$"userId={userId}, title='{title}', message='{message}', tfaEnabled={tfaEnabled}.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user