add life policy aggregate
Some checks failed
Build and Publish / build-release (push) Failing after 38s
Some checks failed
Build and Publish / build-release (push) Failing after 38s
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
defmodule PolicyService.Aggregates.FirePolicyApplication do
|
||||
use PolicyService.Aggregates.PolicyApplication,
|
||||
policy_type: "fire",
|
||||
commands: PolicyService.Commands.FirePolicy
|
||||
|
||||
def validate_details(%{property_address: addr, property_value: val})
|
||||
when is_binary(addr) and byte_size(addr) > 0 and is_number(val) and val > 0,
|
||||
do: :ok
|
||||
|
||||
def validate_details(_), do: {:error, :invalid_fire_details}
|
||||
end
|
||||
37
lib/policy_service/aggregates/life_policy_application.ex
Normal file
37
lib/policy_service/aggregates/life_policy_application.ex
Normal file
@@ -0,0 +1,37 @@
|
||||
defmodule PolicyService.Aggregates.LifePolicyApplication do
|
||||
use PolicyService.Aggregates.PolicyApplication,
|
||||
policy_type: "life",
|
||||
commands: PolicyService.Commands.LifePolicy
|
||||
|
||||
@valid_coverage_types ~w(banking protection)
|
||||
|
||||
def validate_details(%{
|
||||
"coverage_type" => coverage_type,
|
||||
"coverage_amount" => coverage_amount,
|
||||
"coverage_years" => coverage_years,
|
||||
"smoker" => smoker,
|
||||
"medications" => medications,
|
||||
"surgeries" => surgeries,
|
||||
"weight" => weight,
|
||||
"height" => height
|
||||
})
|
||||
when is_binary(coverage_type) and byte_size(coverage_type) > 0 and
|
||||
is_number(coverage_amount) and coverage_amount > 0 and
|
||||
is_integer(coverage_years) and coverage_years > 0 and
|
||||
is_boolean(smoker) and
|
||||
is_list(medications) and
|
||||
is_list(surgeries) and
|
||||
is_number(weight) and weight > 0 and
|
||||
is_number(height) and height > 0 do
|
||||
cond do
|
||||
coverage_type not in @valid_coverage_types -> {:error, :invalid_coverage_type}
|
||||
coverage_years > 100 -> {:error, :invalid_coverage_years}
|
||||
true -> :ok
|
||||
end
|
||||
end
|
||||
|
||||
def validate_details(_), do: {:error, :invalid_life_details}
|
||||
|
||||
def validate_insured(%{"type" => "corporate"}), do: {:error, :life_insurance_requires_individual}
|
||||
def validate_insured(insured), do: super(insured)
|
||||
end
|
||||
@@ -1,8 +0,0 @@
|
||||
defmodule PolicyService.Commands.FirePolicy do
|
||||
defmodule SubmitPolicyApplication,
|
||||
do: use(PolicyService.Commands.Policy.SubmitPolicyApplication)
|
||||
|
||||
defmodule RecordProviderQuote, do: use(PolicyService.Commands.Policy.RecordProviderQuote)
|
||||
defmodule AcceptQuoteAndSolicit, do: use(PolicyService.Commands.Policy.AcceptQuoteAndSolicit)
|
||||
defmodule RecordPolicyIssued, do: use(PolicyService.Commands.Policy.RecordPolicyIssued)
|
||||
end
|
||||
Reference in New Issue
Block a user