Refines user creation email uniqueness check

Improves email duplicate detection by adding specific constraint name validation

Prevents potential false positives in unique email constraint handling
Ensures more precise exception handling for email registration
This commit is contained in:
Janus C. H. Knudsen 2026-01-08 22:52:57 +01:00
parent a991dcdb97
commit e5e7c1c19f

View file

@ -14,8 +14,6 @@ namespace PlanTempus.Components.Users.Create
{ {
public async Task<CommandResponse> Handle(CreateUserCommand command) public async Task<CommandResponse> Handle(CreateUserCommand command)
{ {
command.TransactionId = Guid.NewGuid();
using var db = databaseOperations.CreateScope(nameof(CreateUserHandler)); using var db = databaseOperations.CreateScope(nameof(CreateUserHandler));
try try
{ {
@ -41,7 +39,7 @@ namespace PlanTempus.Components.Users.Create
return new CommandResponse(command.CorrelationId, command.GetType().Name, command.TransactionId); return new CommandResponse(command.CorrelationId, command.GetType().Name, command.TransactionId);
} }
catch (PostgresException ex) when (ex.SqlState == "23505") catch (PostgresException ex) when (ex.SqlState == "23505" && ex.ConstraintName.Equals("users_email_key", StringComparison.InvariantCultureIgnoreCase))
{ {
db.Error(ex); db.Error(ex);
throw new EmailAlreadyRegistreredException(); throw new EmailAlreadyRegistreredException();