rename policy_details to insured_object
All checks were successful
Build and Publish / build-release (push) Successful in 1m36s
All checks were successful
Build and Publish / build-release (push) Successful in 1m36s
This commit is contained in:
@@ -6,7 +6,7 @@ defmodule PolicyService.Aggregates.CarPolicyApplication do
|
||||
@valid_use_types ~w(private commercial bus taxi school)
|
||||
@valid_car_types ~w(sedan suv hatchback coupe convertible pickup van minivan truck)
|
||||
|
||||
def validate_details(%{
|
||||
def validate_insured_object(%{
|
||||
"plate" => plate,
|
||||
"make" => make,
|
||||
"model" => model,
|
||||
@@ -32,7 +32,7 @@ defmodule PolicyService.Aggregates.CarPolicyApplication do
|
||||
end
|
||||
end
|
||||
|
||||
def validate_details(%{
|
||||
def validate_insured_object(%{
|
||||
"plate" => plate,
|
||||
"make" => make,
|
||||
"model" => model,
|
||||
@@ -61,5 +61,5 @@ defmodule PolicyService.Aggregates.CarPolicyApplication do
|
||||
end
|
||||
end
|
||||
|
||||
def validate_details(_), do: {:error, :invalid_car_details}
|
||||
def validate_insured_object(_), do: {:error, :invalid_car_details}
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ defmodule PolicyService.Aggregates.FireContentsPolicyApplication do
|
||||
policy_type: "fire_contents",
|
||||
commands: PolicyService.Commands.FireContentsPolicy
|
||||
|
||||
def validate_details(%{
|
||||
def validate_insured_object(%{
|
||||
"location" => location,
|
||||
"contents_value" => value,
|
||||
"property_use" => use_type,
|
||||
@@ -18,5 +18,5 @@ defmodule PolicyService.Aggregates.FireContentsPolicyApplication do
|
||||
:ok
|
||||
end
|
||||
|
||||
def validate_details(_), do: {:error, :invalid_fire_contents_details}
|
||||
def validate_insured_object(_), do: {:error, :invalid_fire_contents_details}
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ defmodule PolicyService.Aggregates.FireStructurePolicyApplication do
|
||||
policy_type: "fire_structure",
|
||||
commands: PolicyService.Commands.FireStructurePolicy
|
||||
|
||||
def validate_details(%{
|
||||
def validate_insured_object(%{
|
||||
"location" => location,
|
||||
"property_value" => value,
|
||||
"property_use" => use_type,
|
||||
@@ -18,5 +18,5 @@ defmodule PolicyService.Aggregates.FireStructurePolicyApplication do
|
||||
:ok
|
||||
end
|
||||
|
||||
def validate_details(_), do: {:error, :invalid_fire_structure_details}
|
||||
def validate_insured_object(_), do: {:error, :invalid_fire_structure_details}
|
||||
end
|
||||
|
||||
@@ -5,7 +5,7 @@ defmodule PolicyService.Aggregates.LifePolicyApplication do
|
||||
|
||||
@valid_coverage_types ~w(banking protection)
|
||||
|
||||
def validate_details(%{
|
||||
def validate_insured_object(%{
|
||||
"coverage_type" => coverage_type,
|
||||
"coverage_amount" => coverage_amount,
|
||||
"coverage_years" => coverage_years,
|
||||
@@ -30,7 +30,7 @@ defmodule PolicyService.Aggregates.LifePolicyApplication do
|
||||
end
|
||||
end
|
||||
|
||||
def validate_details(_), do: {:error, :invalid_life_details}
|
||||
def validate_insured_object(_), do: {:error, :invalid_life_details}
|
||||
|
||||
def validate_insured(%{"type" => "corporate"}), do: {:error, :life_insurance_requires_individual}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
@moduledoc """
|
||||
Behaviour and __using__ macro for policy application aggregates.
|
||||
Each policy type implements validate_details/1 and declares its detail fields.
|
||||
Each policy type implements validate_insured_object/1 and declares its insured object fields.
|
||||
|
||||
Usage:
|
||||
defmodule PolicyService.Aggregates.CarPolicyApplication do
|
||||
@@ -10,7 +10,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
end
|
||||
"""
|
||||
|
||||
@callback validate_details(map()) :: :ok | {:error, term()}
|
||||
@callback validate_insured_object(map()) :: :ok | {:error, term()}
|
||||
|
||||
defmacro __using__(opts) do
|
||||
policy_type = Keyword.fetch!(opts, :policy_type)
|
||||
@@ -41,7 +41,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
:submitted_by,
|
||||
:insured,
|
||||
:buyer,
|
||||
:policy_details,
|
||||
:insured_object,
|
||||
:selected_providers,
|
||||
:accepted_plan_id,
|
||||
:accepted_by,
|
||||
@@ -61,7 +61,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
:ok <- validate_insured(cmd.insured),
|
||||
:ok <-
|
||||
PolicyService.Aggregates.PolicyApplication.validate_buyer(cmd.buyer),
|
||||
:ok <- validate_details(cmd.policy_details),
|
||||
:ok <- validate_insured_object(cmd.insured_object),
|
||||
:ok <-
|
||||
PolicyService.Aggregates.PolicyApplication.validate_providers(
|
||||
cmd.selected_providers
|
||||
@@ -74,7 +74,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
provider_email: provider.email,
|
||||
insured: cmd.insured,
|
||||
buyer: cmd.buyer,
|
||||
policy_details: cmd.policy_details,
|
||||
insured_object: cmd.insured_object,
|
||||
requested_at: DateTime.utc_now()
|
||||
}
|
||||
end)
|
||||
@@ -85,7 +85,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
submitted_by: cmd.submitted_by,
|
||||
insured: cmd.insured,
|
||||
buyer: cmd.buyer,
|
||||
policy_details: cmd.policy_details,
|
||||
insured_object: cmd.insured_object,
|
||||
selected_providers: cmd.selected_providers,
|
||||
submitted_at: DateTime.utc_now()
|
||||
}
|
||||
@@ -192,7 +192,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do
|
||||
submitted_by: e.submitted_by,
|
||||
insured: e.insured,
|
||||
buyer: e.buyer,
|
||||
policy_details: e.policy_details,
|
||||
insured_object: e.insured_object,
|
||||
selected_providers: e.selected_providers,
|
||||
quotes: %{},
|
||||
state: :awaiting_quotes
|
||||
|
||||
@@ -13,7 +13,7 @@ defmodule PolicyService.Commands.Policy do
|
||||
field :submitted_by, String.t(), enforce: true
|
||||
field :insured, map(), enforce: true
|
||||
field :buyer, map(), enforce: true
|
||||
field :policy_details, map()
|
||||
field :insured_object, map()
|
||||
field :selected_providers, list(), enforce: true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,7 +34,7 @@ defmodule PolicyService.Events.Policy do
|
||||
:submitted_by,
|
||||
:insured,
|
||||
:buyer,
|
||||
:policy_details,
|
||||
:insured_object,
|
||||
:selected_providers,
|
||||
:submitted_at
|
||||
]
|
||||
@@ -49,7 +49,7 @@ defmodule PolicyService.Events.Policy do
|
||||
:provider_email,
|
||||
:insured,
|
||||
:buyer,
|
||||
:policy_details,
|
||||
:insured_object,
|
||||
:requested_at
|
||||
]
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ defmodule PolicyService.Projections.PolicyApplication do
|
||||
:policy_type,
|
||||
:insured,
|
||||
:buyer,
|
||||
:policy_details,
|
||||
:insured_object,
|
||||
:selected_providers,
|
||||
:quotes,
|
||||
:accepted_plan_id,
|
||||
@@ -53,7 +53,7 @@ defmodule PolicyService.Projections.PolicyApplication do
|
||||
|
||||
field :insured, :map
|
||||
field :buyer, :map
|
||||
field :policy_details, :map
|
||||
field :insured_object, :map
|
||||
|
||||
field :selected_providers, {:array, :string}, default: []
|
||||
field :quotes, :map, default: %{}
|
||||
|
||||
@@ -26,7 +26,7 @@ defmodule PolicyService.Projectors.PolicyProjector do
|
||||
policy_type: e.id.policy_type,
|
||||
insured: atomize(e.insured),
|
||||
buyer: atomize(e.buyer),
|
||||
policy_details: atomize(e.policy_details),
|
||||
insured_object: atomize(e.insured_object),
|
||||
selected_providers: Enum.map(e.selected_providers, & &1["provider_id"]),
|
||||
quotes: %{},
|
||||
status: "quote_requested",
|
||||
|
||||
Reference in New Issue
Block a user