fix search and insured override
All checks were successful
Build and Publish / build-release (push) Successful in 1m50s

This commit is contained in:
2026-04-30 11:35:27 -05:00
parent b5686f890a
commit 42cb25a3b6
3 changed files with 34 additions and 27 deletions

View File

@@ -58,8 +58,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
@impl Commanded.Aggregates.Aggregate
def execute(%__MODULE__{state: nil}, %SubmitPolicyApplication{} = cmd) do
with :ok <- PolicyService.Aggregates.PolicyApplication.validate_policy_id(cmd.id),
:ok <-
PolicyService.Aggregates.PolicyApplication.validate_insured(cmd.insured),
:ok <- validate_insured(cmd.insured),
:ok <-
PolicyService.Aggregates.PolicyApplication.validate_buyer(cmd.buyer),
:ok <- validate_details(cmd.policy_details),
@@ -242,8 +241,32 @@ defmodule PolicyService.Aggregates.PolicyApplication do
}
end
# ── Validation ───────────────────────────────────────────────────
def validate_insured(%{
"type" => "individual",
"name" => n,
"date_of_birth" => _,
"document_id" => d
})
when is_binary(n) and is_binary(d) and byte_size(n) > 0 and byte_size(d) > 0,
do: :ok
def validate_insured(%{
"type" => "corporate",
"company_name" => c,
"ruc" => r,
"legal_rep_name" => rep,
"legal_rep_document" => rd
})
when is_binary(c) and is_binary(r) and is_binary(rep) and is_binary(rd) and
byte_size(c) > 0 and byte_size(r) > 0,
do: :ok
def validate_insured(_), do: {:error, :invalid_insured_info}
# allow each aggregate to override any callback
defoverridable execute: 2, apply: 2
defoverridable execute: 2, apply: 2, validate_insured: 1
end
end
@@ -253,28 +276,6 @@ defmodule PolicyService.Aggregates.PolicyApplication do
def validate_user(id) when is_binary(id) and byte_size(id) > 0, do: :ok
def validate_user(_), do: {:error, :missing_user_id}
def validate_insured(%{
"type" => "individual",
"name" => n,
"date_of_birth" => _,
"document_id" => d
})
when is_binary(n) and is_binary(d) and byte_size(n) > 0 and byte_size(d) > 0,
do: :ok
def validate_insured(%{
"type" => "corporate",
"company_name" => c,
"ruc" => r,
"legal_rep_name" => rep,
"legal_rep_document" => rd
})
when is_binary(c) and is_binary(r) and is_binary(rep) and is_binary(rd) and
byte_size(c) > 0 and byte_size(r) > 0,
do: :ok
def validate_insured(_), do: {:error, :invalid_insured_info}
def validate_buyer(%{
"type" => "individual",
"name" => n,