refactor buyer and insured and add more policy types
All checks were successful
Build and Publish / build-release (push) Successful in 1m38s

This commit is contained in:
2026-04-27 14:06:28 -05:00
parent c8a58c3f58
commit 2a8f2ffc2d
27 changed files with 676 additions and 170 deletions

View File

@@ -11,21 +11,52 @@ defmodule PolicyService.Aggregates.CarPolicyApplication do
"make" => make,
"model" => model,
"year" => year,
"car_value" => car_value,
"use_type" => use_type,
"car_type" => car_type,
"rc_limits" => _rc_limits,
"market_value" => market_value,
"requested_value" => requested_value
})
when is_binary(plate) and is_binary(make) and is_binary(model) and
is_integer(year) and
is_number(market_value) and market_value > 0 and
is_number(requested_value) and requested_value > 0 and
is_binary(use_type) and byte_size(use_type) > 0 and
is_binary(car_type) and byte_size(car_type) > 0 do
cond do
year < 1886 or year > Date.utc_today().year + 1 -> {:error, :invalid_car_year}
use_type not in @valid_use_types -> {:error, :invalid_use_type}
car_type not in @valid_car_types -> {:error, :invalid_car_type}
byte_size(plate) == 0 -> {:error, :missing_plate}
true -> :ok
end
end
def validate_details(%{
"plate" => plate,
"make" => make,
"model" => model,
"year" => year,
"use_type" => use_type,
"car_type" => car_type,
"chassis_number" => chassis,
"engine_number" => engine
"engine_number" => engine,
"rc_limits" => _rc_limits,
"market_value" => market_value,
"requested_value" => requested_value
})
when is_binary(plate) and is_binary(make) and is_binary(model) and
is_integer(year) and is_number(car_value) and car_value > 0 and
is_integer(year) and
is_number(market_value) and market_value > 0 and
is_number(requested_value) and requested_value > 0 and
is_binary(use_type) and byte_size(use_type) > 0 and
is_binary(car_type) and byte_size(car_type) > 0 and
is_binary(chassis) and is_binary(engine) do
cond do
year < 1886 or year > Date.utc_today().year + 1 -> {:error, :invalid_car_year}
use_type not in @valid_use_types -> {:error, :invalid_use_type}
car_type not in @valid_car_types -> {:error, :invalid_car_type}
byte_size(chassis) == 0 -> {:error, :missing_chassis_number}
byte_size(engine) == 0 -> {:error, :missing_engine_number}
byte_size(plate) == 0 -> {:error, :missing_plate}
true -> :ok
end
end