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

@@ -33,5 +33,11 @@ defmodule PolicyService.Aggregates.LifePolicyApplication do
def validate_details(_), do: {:error, :invalid_life_details} def validate_details(_), do: {:error, :invalid_life_details}
def validate_insured(%{"type" => "corporate"}), do: {:error, :life_insurance_requires_individual} def validate_insured(%{"type" => "corporate"}), do: {:error, :life_insurance_requires_individual}
def validate_insured(insured), do: super(insured)
def validate_insured(%{"type" => "individual", "gender" => gender} = insured)
when is_binary(gender) and byte_size(gender) > 0 do
super(insured)
end
def validate_insured(%{"type" => "individual"}), do: {:error, :missing_gender}
end end

View File

@@ -58,8 +58,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
@impl Commanded.Aggregates.Aggregate @impl Commanded.Aggregates.Aggregate
def execute(%__MODULE__{state: nil}, %SubmitPolicyApplication{} = cmd) do def execute(%__MODULE__{state: nil}, %SubmitPolicyApplication{} = cmd) do
with :ok <- PolicyService.Aggregates.PolicyApplication.validate_policy_id(cmd.id), with :ok <- PolicyService.Aggregates.PolicyApplication.validate_policy_id(cmd.id),
:ok <- :ok <- validate_insured(cmd.insured),
PolicyService.Aggregates.PolicyApplication.validate_insured(cmd.insured),
:ok <- :ok <-
PolicyService.Aggregates.PolicyApplication.validate_buyer(cmd.buyer), PolicyService.Aggregates.PolicyApplication.validate_buyer(cmd.buyer),
:ok <- validate_details(cmd.policy_details), :ok <- validate_details(cmd.policy_details),
@@ -242,16 +241,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
} }
end end
# allow each aggregate to override any callback # ── Validation ───────────────────────────────────────────────────
defoverridable execute: 2, apply: 2
end
end
def validate_policy_id(%PolicyService.Aggregates.PolicyId{policy_type: _}), do: :ok
def validate_policy_id(_), do: {:error, :invalid_policy_id_format}
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(%{ def validate_insured(%{
"type" => "individual", "type" => "individual",
@@ -275,6 +265,17 @@ defmodule PolicyService.Aggregates.PolicyApplication do
def validate_insured(_), do: {:error, :invalid_insured_info} def validate_insured(_), do: {:error, :invalid_insured_info}
# allow each aggregate to override any callback
defoverridable execute: 2, apply: 2, validate_insured: 1
end
end
def validate_policy_id(%PolicyService.Aggregates.PolicyId{policy_type: _}), do: :ok
def validate_policy_id(_), do: {:error, :invalid_policy_id_format}
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_buyer(%{ def validate_buyer(%{
"type" => "individual", "type" => "individual",
"name" => n, "name" => n,

View File

@@ -35,7 +35,7 @@ defmodule PolicyService.Projections.PolicyApplication do
max_limit: 100, max_limit: 100,
custom_fields: [ custom_fields: [
search: [ search: [
filter: {PolicyService.Projections.PolicyApplicationFilters, :search, []}, filter: {PolicyService.Filters.PolicyApplicationFilters, :search, []},
ecto_type: :string, ecto_type: :string,
operators: [:==] operators: [:==]
] ]