Skip to content

Commit

Permalink
fix: or-2006 add extra duplicate check closer to persisting event
Browse files Browse the repository at this point in the history
  • Loading branch information
koenmetsu committed Dec 7, 2023
1 parent f78528f commit 9d69705
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<Result> Handle(CommandEnvelope<RegistreerVerenigingUitKboComma

if (vereniging.IsFailure()) throw new GeenGeldigeVerenigingInKbo();

return Result.Success(await RegistreerVereniging(vereniging, message.Metadata, cancellationToken));
return await RegistreerVereniging(vereniging, message.Metadata, cancellationToken);
}

private async Task<Result> CheckForDuplicate(KboNummer kboNummer)
Expand All @@ -45,16 +45,20 @@ private async Task<Result> CheckForDuplicate(KboNummer kboNummer)
return duplicateKbo is not null ? DuplicateKboFound.WithVcode(duplicateKbo.VCode!) : Result.Success();
}

private async Task<CommandResult> RegistreerVereniging(VerenigingVolgensKbo verenigingVolgensKbo, CommandMetadata messageMetadata, CancellationToken cancellationToken)
private async Task<Result> RegistreerVereniging(VerenigingVolgensKbo verenigingVolgensKbo, CommandMetadata messageMetadata, CancellationToken cancellationToken)
{
var vCode = await _vCodeService.GetNext();

var vereniging = VerenigingMetRechtspersoonlijkheid.Registreer(
vCode,
verenigingVolgensKbo);

var duplicateResult = await CheckForDuplicate(verenigingVolgensKbo.KboNummer);

if (duplicateResult.IsFailure()) return duplicateResult;

var result = await _verenigingsRepository.Save(vereniging, messageMetadata, cancellationToken);

return CommandResult.Create(vCode, result);
return Result.Success(CommandResult.Create(vCode, result));
}
}

0 comments on commit 9d69705

Please sign in to comment.