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
|
|
||||||
@@ -300,6 +300,7 @@ defmodule PolicyServiceWeb.PolicyController do
|
|||||||
"name" => info["name"],
|
"name" => info["name"],
|
||||||
"date_of_birth" => dob,
|
"date_of_birth" => dob,
|
||||||
"document_id" => info["document_id"],
|
"document_id" => info["document_id"],
|
||||||
|
"gender" => info["gender"],
|
||||||
"email" => info["email"],
|
"email" => info["email"],
|
||||||
"phone" => info["phone"],
|
"phone" => info["phone"],
|
||||||
"address" => info["address"]
|
"address" => info["address"]
|
||||||
@@ -379,7 +380,10 @@ defmodule PolicyServiceWeb.PolicyController do
|
|||||||
"car_type" => d["car_type"],
|
"car_type" => d["car_type"],
|
||||||
"chassis_number" => d["chassis_number"],
|
"chassis_number" => d["chassis_number"],
|
||||||
"engine_number" => d["engine_number"],
|
"engine_number" => d["engine_number"],
|
||||||
"rc_limits" => d["rc_limits"],
|
"rc_limits" => %{
|
||||||
|
"bodily_injury" => d["rc_limits"]["bodily_injury"],
|
||||||
|
"property_damage" => d["rc_limits"]["property_damage"]
|
||||||
|
},
|
||||||
"market_value" => d["market_value"],
|
"market_value" => d["market_value"],
|
||||||
"requested_value" => d["requested_value"]
|
"requested_value" => d["requested_value"]
|
||||||
}}
|
}}
|
||||||
@@ -395,8 +399,8 @@ defmodule PolicyServiceWeb.PolicyController do
|
|||||||
"coverage_amount" => d["coverage_amount"],
|
"coverage_amount" => d["coverage_amount"],
|
||||||
"coverage_years" => d["coverage_years"],
|
"coverage_years" => d["coverage_years"],
|
||||||
"smoker" => d["smoker"],
|
"smoker" => d["smoker"],
|
||||||
"medications" => d["medications"],
|
"medications" => d["medications"] || [],
|
||||||
"surgeries" => d["surgeries"],
|
"surgeries" => d["surgeries"] || [],
|
||||||
"weight" => d["weight"],
|
"weight" => d["weight"],
|
||||||
"height" => d["height"]
|
"height" => d["height"]
|
||||||
}}
|
}}
|
||||||
@@ -411,7 +415,7 @@ defmodule PolicyServiceWeb.PolicyController do
|
|||||||
"location" => d["location"],
|
"location" => d["location"],
|
||||||
"property_value" => d["property_value"],
|
"property_value" => d["property_value"],
|
||||||
"property_use" => d["property_use"],
|
"property_use" => d["property_use"],
|
||||||
"security_measures" => d["security_measures"],
|
"security_measures" => d["security_measures"] || [],
|
||||||
"market_value" => d["market_value"]
|
"market_value" => d["market_value"]
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
@@ -425,8 +429,8 @@ defmodule PolicyServiceWeb.PolicyController do
|
|||||||
"location" => d["location"],
|
"location" => d["location"],
|
||||||
"contents_value" => d["contents_value"],
|
"contents_value" => d["contents_value"],
|
||||||
"property_use" => d["property_use"],
|
"property_use" => d["property_use"],
|
||||||
"security_measures" => d["security_measures"],
|
"security_measures" => d["security_measures"] || [],
|
||||||
"high_value_items" => d["high_value_items"]
|
"high_value_items" => d["high_value_items"] || []
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -24,12 +24,13 @@ defmodule PolicyServiceWeb.Schemas.Policy do
|
|||||||
OpenApiSpex.schema(%{
|
OpenApiSpex.schema(%{
|
||||||
title: "InsuredIndividual",
|
title: "InsuredIndividual",
|
||||||
type: :object,
|
type: :object,
|
||||||
required: [:type, :name, :date_of_birth, :document_id],
|
required: [:type, :name, :date_of_birth, :document_id, :gender],
|
||||||
properties: %{
|
properties: %{
|
||||||
type: %Schema{type: :string, enum: ["individual"]},
|
type: %Schema{type: :string, enum: ["individual"]},
|
||||||
name: %Schema{type: :string, example: "Juan Pérez"},
|
name: %Schema{type: :string, example: "Juan Pérez"},
|
||||||
date_of_birth: %Schema{type: :string, format: :date, example: "1985-06-15"},
|
date_of_birth: %Schema{type: :string, format: :date, example: "1985-06-15"},
|
||||||
document_id: %Schema{type: :string, example: "8-123-456"},
|
document_id: %Schema{type: :string, example: "8-123-456"},
|
||||||
|
gender: %Schema{type: :string, enum: ["male", "female"], example: "male"},
|
||||||
email: %Schema{type: :string, format: :email, example: "juan@example.com"},
|
email: %Schema{type: :string, format: :email, example: "juan@example.com"},
|
||||||
phone: %Schema{type: :string, example: "+507-1234-5678"},
|
phone: %Schema{type: :string, example: "+507-1234-5678"},
|
||||||
address: %Schema{type: :string, example: "Calle 50, Panama City"}
|
address: %Schema{type: :string, example: "Calle 50, Panama City"}
|
||||||
@@ -220,7 +221,7 @@ defmodule PolicyServiceWeb.Schemas.Policy do
|
|||||||
OpenApiSpex.schema(%{
|
OpenApiSpex.schema(%{
|
||||||
title: "LifePolicyDetails",
|
title: "LifePolicyDetails",
|
||||||
type: :object,
|
type: :object,
|
||||||
required: [:coverage_type, :coverage_amount, :coverage_years, :smoker, :weight, :height],
|
required: [:coverage_type, :coverage_amount, :coverage_years, :smoker],
|
||||||
properties: %{
|
properties: %{
|
||||||
coverage_type: %Schema{
|
coverage_type: %Schema{
|
||||||
type: :string,
|
type: :string,
|
||||||
@@ -229,8 +230,8 @@ defmodule PolicyServiceWeb.Schemas.Policy do
|
|||||||
coverage_amount: %Schema{type: :number, example: 100_000},
|
coverage_amount: %Schema{type: :number, example: 100_000},
|
||||||
coverage_years: %Schema{type: :integer, example: 10},
|
coverage_years: %Schema{type: :integer, example: 10},
|
||||||
smoker: %Schema{type: :boolean, example: false},
|
smoker: %Schema{type: :boolean, example: false},
|
||||||
medications: %Schema{type: :array, items: %Schema{type: :string}},
|
medications: %Schema{type: :array, items: %Schema{type: :string}, example: ["Aspirin", "Lisinopril"]},
|
||||||
surgeries: %Schema{type: :array, items: %Schema{type: :string}},
|
surgeries: %Schema{type: :array, items: %Schema{type: :string}, example: ["Appendectomy, 2015"]},
|
||||||
weight: %Schema{type: :number, example: 70},
|
weight: %Schema{type: :number, example: 70},
|
||||||
height: %Schema{type: :number, example: 175}
|
height: %Schema{type: :number, example: 175}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user