diff --git a/.gitignore b/.gitignore index 83bb19e..b15141c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +/.direnv/ +/result + # The directory Mix will write compiled artifacts to. /_build/ @@ -23,5 +26,67 @@ erl_crash.dump /tmp/ # Ignore package tarball (built via "mix hex.build"). -policy_service-*.tar +plausible-*.tar +# If NPM crashes, it generates a log, let's ignore it too. +npm-debug.log + +# If running Clickhouse through the Makefile, its data is written here +/.clickhouse_db_vol/ + +# The directory NPM downloads your dependencies sources to. +/assets/node_modules/ +/tracker/node_modules/ + +# Files generated by Playwright when running tracker tests +/tracker/test-results/ +/tracker/playwright-report/ +/tracker/blob-report/ +/tracker/playwright/.cache/ + +# Stored hash of source tracker files used in development environment +# to detect changes in /tracker/src and avoid unnecessary compilation. +/tracker/compiler/last-hash.txt +# Temporary file used by analyze-sizes.js +/tracker/compiler/.analyze-sizes.json + +# Tracker npm module files that are generated by the compiler for the NPM package +/tracker/npm_package/plausible.js* +/tracker/npm_package/plausible.cjs* +/tracker/npm_package/plausible.d.cts + +# test coverage directory +/assets/coverage + +# Since we are building assets from assets/, +# we ignore priv/static. You may want to comment +# this depending on your deployment strategy. +/priv/static/css +/priv/static/js +/priv/version.json + +# Files matching config/*.secret.exs pattern contain sensitive +# data and you should not commit them into version control. +# +# Alternatively, you may comment the line below and commit the +# secrets files as long as you replace their contents by environment +# variables. +/config/*.secret.exs + +# Ignore Elixir Language Server files +.elixir_ls +plausible-report.xml + +.idea +*.iml +*.log +*.code-workspace +.vscode + +# Dializer +/priv/plts/*.plt +/priv/plts/*.plt.hash + +.env + +.claude diff --git a/flake.nix b/flake.nix index 7c3802c..82e6675 100644 --- a/flake.nix +++ b/flake.nix @@ -21,7 +21,7 @@ mixFodDeps = beamPackages.fetchMixDeps { inherit pname version; src = ./.; - sha256 = "sha256-yqxq5pB7dKEhCZiJWXrKKCra45hxfyyfpP/zyNLEF7A="; + sha256 = "sha256-ZyrQiL5sOCC+V9S7rVGrCNEqm/TDZkjIx6Y+MZy7+6s="; }; package = beamPackages.mixRelease { inherit pname version mixFodDeps; diff --git a/lib/policy_service/aggregates/policy_application.ex b/lib/policy_service/aggregates/policy_application.ex index b86a51c..9e2f288 100644 --- a/lib/policy_service/aggregates/policy_application.ex +++ b/lib/policy_service/aggregates/policy_application.ex @@ -30,7 +30,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do ProviderQuoteReceived, AllQuotesReceived, QuoteAccepted, - SolicitationSent, + SolicitationRequestSent, PolicyIssued } @@ -42,16 +42,14 @@ defmodule PolicyService.Aggregates.PolicyApplication do :applicant_info, :policy_details, :selected_providers, - :accepted_quote_id, :accepted_plan_id, - :accepted_provider_id, - :solicitation_id, - :policy_number, + :accepted_by, + :provider_policy_number, :effective_date, :expiry_date, :state, quotes: %{}, - pending_endorsements: %{} + endorsements: %{} ] # ── Execute ──────────────────────────────────────────────────────────── @@ -140,19 +138,29 @@ defmodule PolicyService.Aggregates.PolicyApplication do end def execute(%__MODULE__{} = agg, %AcceptQuoteAndSolicit{} = cmd) do - with {:ok, quote} <- - PolicyService.Aggregates.PolicyApplication.find_quote(agg, cmd.quote_id), - {:ok, provider} <- - PolicyService.Aggregates.PolicyApplication.find_provider(agg, quote.provider_id), - {:ok, plan} <- - PolicyService.Aggregates.PolicyApplication.find_plan(quote, cmd.plan_id) do - %QuoteAccepted{ - id: agg.id, - quote: quote, - plan: plan, - provider: provider, - accepted_at: DateTime.utc_now() - } + case Enum.find_value(agg.quotes, fn {provider_id, quote} -> + case Enum.find(quote.plans, &(&1.plan_id == cmd.accepted_plan_id)) do + nil -> nil + plan -> {:ok, %{quote: quote, provider: provider_id, plan: plan}} + end + end) do + nil -> + {:error, :plan_not_found} + + result -> + [ + %QuoteAccepted{ + id: agg.id, + quote: result.quote, + plan: result.plan, + provider: result.provider, + accepted_by: cmd.accepted_by + }, + %SolicitationRequestSent{ + id: agg.id, + plan: result.plan + } + ] end end @@ -162,7 +170,7 @@ defmodule PolicyService.Aggregates.PolicyApplication do def execute(%__MODULE__{} = agg, %RecordPolicyIssued{} = cmd) do %PolicyIssued{ id: agg.id, - policy_number: cmd.policy_number, + provider_policy_number: cmd.provider_policy_number, effective_date: cmd.effective_date, expiry_date: cmd.expiry_date, issued_at: cmd.issued_at || DateTime.utc_now() @@ -205,21 +213,22 @@ defmodule PolicyService.Aggregates.PolicyApplication do def apply(%__MODULE__{} = agg, %QuoteAccepted{} = e) do %__MODULE__{ agg - | accepted_quote_id: e.quote.quote_id, - accepted_plan_id: e.plan.plan_id, - accepted_provider_id: e.provider.provider_id, - state: :solicitation_sent + | accepted_plan_id: e.plan.plan_id, + accepted_by: e.accepted_by } end - def apply(%__MODULE__{} = agg, %SolicitationSent{} = e) do - %__MODULE__{agg | solicitation_id: e.solicitation_id} + def apply(%__MODULE__{} = agg, %SolicitationRequestSent{} = _e) do + %__MODULE__{ + agg + | state: :awaiting_policy + } end def apply(%__MODULE__{} = agg, %PolicyIssued{} = e) do %__MODULE__{ agg - | policy_number: e.policy_number, + | provider_policy_number: e.provider_policy_number, effective_date: e.effective_date, expiry_date: e.expiry_date, state: :issued diff --git a/lib/policy_service/aggregates/policy_id.ex b/lib/policy_service/aggregates/policy_id.ex index b0b8740..17c3bc5 100644 --- a/lib/policy_service/aggregates/policy_id.ex +++ b/lib/policy_service/aggregates/policy_id.ex @@ -1,4 +1,9 @@ defmodule PolicyService.Aggregates.PolicyId do + @type t :: %__MODULE__{ + org_id: String.t(), + policy_type: String.t(), + application_id: String.t() + } @derive Jason.Encoder defstruct [:org_id, :policy_type, :application_id] diff --git a/lib/policy_service/commanded_app.ex b/lib/policy_service/commanded_app.ex index c874b22..7508283 100644 --- a/lib/policy_service/commanded_app.ex +++ b/lib/policy_service/commanded_app.ex @@ -31,4 +31,4 @@ defmodule PolicyService.CommandedApp do otp_app: :policy_service router(PolicyService.Router) -end +end \ No newline at end of file diff --git a/lib/policy_service/commands/car_policy.ex b/lib/policy_service/commands/car_policy.ex index f1556df..792ab50 100644 --- a/lib/policy_service/commands/car_policy.ex +++ b/lib/policy_service/commands/car_policy.ex @@ -1,8 +1,6 @@ defmodule PolicyService.Commands.CarPolicy do - alias PolicyService.Commands.Policy - - defmodule SubmitPolicyApplication, do: use(Policy.SubmitPolicyApplication) - defmodule RecordProviderQuote, do: use(Policy.RecordProviderQuote) - defmodule AcceptQuoteAndSolicit, do: use(Policy.AcceptQuoteAndSolicit) - defmodule RecordPolicyIssued, do: use(Policy.RecordPolicyIssued) -end + 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 \ No newline at end of file diff --git a/lib/policy_service/commands/fire_policy.ex b/lib/policy_service/commands/fire_policy.ex index 6bc5b7f..77eefbb 100644 --- a/lib/policy_service/commands/fire_policy.ex +++ b/lib/policy_service/commands/fire_policy.ex @@ -1,8 +1,6 @@ defmodule PolicyService.Commands.FirePolicy do - alias PolicyService.Commands.Policy - - defmodule SubmitPolicyApplication, do: use(Policy.SubmitPolicyApplication) - defmodule RecordProviderQuote, do: use(Policy.RecordProviderQuote) - defmodule AcceptQuoteAndSolicit, do: use(Policy.AcceptQuoteAndSolicit) - defmodule RecordPolicyIssued, do: use(Policy.RecordPolicyIssued) -end + 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 \ No newline at end of file diff --git a/lib/policy_service/commands/policy.ex b/lib/policy_service/commands/policy.ex index 5edc53b..a7aecd1 100644 --- a/lib/policy_service/commands/policy.ex +++ b/lib/policy_service/commands/policy.ex @@ -1,19 +1,20 @@ defmodule PolicyService.Commands.Policy do @moduledoc """ - Base templates for Policy commands. - Use these macros to ensure all policy types share the same structure. + Base templates for Policy commands using TypedStruct. """ defmodule SubmitPolicyApplication do defmacro __using__(_opts) do quote do - defstruct [ - :id, - :submitted_by, - :applicant_info, - :policy_details, - :selected_providers - ] + use TypedStruct + + typedstruct do + field :id, PolicyService.Aggregates.PolicyId.t(), enforce: true + field :submitted_by, String.t(), enforce: true + field :applicant_info, map(), enforce: true + field :policy_details, map() + field :selected_providers, list(), enforce: true + end end end end @@ -21,16 +22,18 @@ defmodule PolicyService.Commands.Policy do defmodule RecordProviderQuote do defmacro __using__(_opts) do quote do - defstruct [ - :id, - :recorded_by, - :provider_id, - :quote_id, - :premium, - :coverage_details, - :valid_until, - :plans - ] + use TypedStruct + + typedstruct do + field :id, PolicyService.Aggregates.PolicyId.t(), enforce: true + field :recorded_by, String.t(), enforce: true + field :provider_id, String.t(), enforce: true + field :quote_id, String.t(), enforce: true + field :premium, String.t() + field :coverage_details, map() + field :valid_until, String.t(), enforce: true + field :plans, list(), enforce: true + end end end end @@ -38,13 +41,13 @@ defmodule PolicyService.Commands.Policy do defmodule AcceptQuoteAndSolicit do defmacro __using__(_opts) do quote do - defstruct [ - :id, - :accepted_by, - :quote_id, - :plan_id, - :solicitation_fields - ] + use TypedStruct + + typedstruct do + field :id, PolicyService.Aggregates.PolicyId.t(), enforce: true + field :accepted_by, String.t(), enforce: true + field :accepted_plan_id, String.t(), enforce: true + end end end end @@ -52,14 +55,16 @@ defmodule PolicyService.Commands.Policy do defmodule RecordPolicyIssued do defmacro __using__(_opts) do quote do - defstruct [ - :id, - :policy_number, - :effective_date, - :expiry_date, - :issued_at - ] + use TypedStruct + + typedstruct do + field :id, PolicyService.Aggregates.PolicyId.t(), enforce: true + field :provider_policy_number, String.t(), enforce: true + field :effective_date, String.t(), enforce: true + field :expiry_date, String.t(), enforce: true + field :issued_at, String.t() + end end end end -end +end \ No newline at end of file diff --git a/lib/policy_service/consumers/policy_issued.ex b/lib/policy_service/consumers/policy_issued.ex index 08b55fd..1603970 100644 --- a/lib/policy_service/consumers/policy_issued.ex +++ b/lib/policy_service/consumers/policy_issued.ex @@ -49,7 +49,7 @@ defmodule PolicyService.Consumers.PolicyIssuedConsumer do "car" -> %CarPolicy.RecordPolicyIssued{ id: event["id"], - policy_number: event["policy_number"], + provider_policy_number: event["provider_policy_number"], effective_date: event["effective_date"], expiry_date: event["expiry_date"], issued_at: DateTime.utc_now() diff --git a/lib/policy_service/events/policy.ex b/lib/policy_service/events/policy.ex index 490b45f..1da7cdd 100644 --- a/lib/policy_service/events/policy.ex +++ b/lib/policy_service/events/policy.ex @@ -50,18 +50,18 @@ defmodule PolicyService.Events.Policy do defmodule QuoteAccepted do use PolicyService.Events @derive Jason.Encoder - defstruct [:id, :accepted_by, :quote, :plan, :provider, :accepted_at] + defstruct [:id, :accepted_by, :quote, :plan, :provider] end - defmodule SolicitationSent do - use PolicyService.Events - @derive Jason.Encoder - defstruct [:id, :solicitation_id, :provider_id, :template_id, :s3_key, :sent_at] - end + defmodule SolicitationRequestSent do + use PolicyService.Events + @derive Jason.Encoder + defstruct [:id, :plan] + end defmodule PolicyIssued do use PolicyService.Events @derive Jason.Encoder - defstruct [:id, :policy_number, :effective_date, :expiry_date, :issued_at] + defstruct [:id, :provider_policy_number, :effective_date, :expiry_date, :issued_at] end end diff --git a/lib/policy_service/handlers/solicitation_request_handler.ex b/lib/policy_service/handlers/solicitation_request_handler.ex index 8d489fb..9686237 100644 --- a/lib/policy_service/handlers/solicitation_request_handler.ex +++ b/lib/policy_service/handlers/solicitation_request_handler.ex @@ -5,11 +5,11 @@ defmodule PolicyService.Handlers.SolicitationRequestHandler do require Logger - alias PolicyService.Events.Policy.QuoteAccepted - alias PolicyService.MessageBus + alias PolicyService.Events.Policy.SolicitationRequestSent + alias PolicyService.MessageBus - def handle(%QuoteAccepted{} = event, _metadata) do - MessageBus.publish("policy_service.events.policy_issued", "quote.accepted", event) - :ok - end + def handle(%SolicitationRequestSent{} = event, _metadata) do + MessageBus.publish("policy_service.events.solicitation_requested", "solicitation.requested", event) + :ok + end end diff --git a/lib/policy_service/policy/filters.ex b/lib/policy_service/policy/filters.ex index d42f7d1..c0f7aeb 100644 --- a/lib/policy_service/policy/filters.ex +++ b/lib/policy_service/policy/filters.ex @@ -11,7 +11,7 @@ defmodule PolicyService.Filters.PolicyApplicationFilters do fragment("?->>'company_name' ilike ?", p.applicant_info, ^term) or fragment("?->>'document_id' ilike ?", p.applicant_info, ^term) or fragment("?->>'ruc' ilike ?", p.applicant_info, ^term) or - ilike(p.policy_number, ^term) + ilike(p.provider_policy_number, ^term) ) end end diff --git a/lib/policy_service/projections/policy.ex b/lib/policy_service/projections/policy.ex index bd3856f..82e3c31 100644 --- a/lib/policy_service/projections/policy.ex +++ b/lib/policy_service/projections/policy.ex @@ -2,34 +2,29 @@ defmodule PolicyService.Projections.PolicyApplication do use Ecto.Schema @derive {Jason.Encoder, - only: [ - :id, - :application_id, - :org_id, - :submitted_by, - :policy_type, - :applicant_info, - :policy_details, - :selected_providers, - :quotes, - :accepted_quote_id, - :accepted_plan_id, - :accepted_provider_id, - :accepted_by, - :accepted_at, - :solicitation_id, - :solicitation_s3_key, - :policy_number, - :premium, - :effective_date, - :expiry_date, - :status, - :submitted_at, - :solicitation_sent_at, - :issued_at, - :inserted_at, - :updated_at - ]} + only: [ + :id, + :application_id, + :org_id, + :submitted_by, + :policy_type, + :applicant_info, + :policy_details, + :selected_providers, + :quotes, + :accepted_plan_id, + :accepted_by, + :provider_policy_number, + :premium, + :effective_date, + :expiry_date, + :status, + :submitted_at, + :solicitation_sent_at, + :issued_at, + :inserted_at, + :updated_at + ]} @derive { Flop.Schema, @@ -61,16 +56,11 @@ defmodule PolicyService.Projections.PolicyApplication do field :selected_providers, {:array, :string}, default: [] field :quotes, :map, default: %{} - field :accepted_quote_id, :string field :accepted_plan_id, :string - field :accepted_provider_id, :string field :accepted_by, :string - field :accepted_at, :utc_datetime_usec - field :solicitation_id, :string - field :solicitation_s3_key, :string + field :provider_policy_number, :string - field :policy_number, :string field :premium, :decimal field :effective_date, :date field :expiry_date, :date diff --git a/lib/policy_service/projectors/policy_projector.ex b/lib/policy_service/projectors/policy_projector.ex index 453b96b..8b15705 100644 --- a/lib/policy_service/projectors/policy_projector.ex +++ b/lib/policy_service/projectors/policy_projector.ex @@ -10,12 +10,11 @@ defmodule PolicyService.Projectors.PolicyProjector do ProviderQuoteReceived, AllQuotesReceived, QuoteAccepted, - SolicitationSent, + SolicitationRequestSent, PolicyIssued } alias PolicyService.Projections.PolicyApplication - alias PolicyService.Aggregates.PolicyId import Ecto.Query project(%PolicyApplicationSubmitted{} = e, _meta, fn multi -> @@ -69,25 +68,20 @@ defmodule PolicyService.Projectors.PolicyProjector do end) |> Ecto.Multi.update(:policy_application, fn %{fetch: p} -> Ecto.Changeset.change(p, - accepted_quote_id: e.quote.quote_id, accepted_plan_id: e.plan.plan_id, - accepted_provider_id: e.provider.id, - accepted_at: parse_datetime(e.accepted_at), - status: "solicitation_sent" + accepted_by: e.accepted_by ) end) end) - project(%SolicitationSent{} = e, _meta, fn multi -> + project(%SolicitationRequestSent{} = e, _meta, fn multi -> multi |> Ecto.Multi.run(:fetch, fn repo, _ -> {:ok, repo.get!(PolicyApplication, to_string(e.id))} end) |> Ecto.Multi.update(:policy_application, fn %{fetch: p} -> Ecto.Changeset.change(p, - solicitation_id: e.solicitation_id, - solicitation_s3_key: e.s3_key, - solicitation_sent_at: parse_datetime(e.sent_at) + status: "awaiting_policy" ) end) end) @@ -99,7 +93,7 @@ defmodule PolicyService.Projectors.PolicyProjector do end) |> Ecto.Multi.update(:policy_application, fn %{fetch: p} -> Ecto.Changeset.change(p, - policy_number: e.policy_number, + provider_policy_number: e.provider_policy_number, effective_date: parse_date(e.effective_date), expiry_date: parse_date(e.expiry_date), issued_at: parse_datetime(e.issued_at), diff --git a/lib/policy_service_web/controllers/policy_controller.ex b/lib/policy_service_web/controllers/policy_controller.ex index 6622835..2da4837 100644 --- a/lib/policy_service_web/controllers/policy_controller.ex +++ b/lib/policy_service_web/controllers/policy_controller.ex @@ -155,9 +155,8 @@ defmodule PolicyServiceWeb.PolicyController do "car" -> %CarPolicy.AcceptQuoteAndSolicit{ id: PolicyId.new(org_id, policy.policy_type, application_id), - quote_id: params["quote_id"], - plan_id: params["plan_id"], - solicitation_fields: params["solicitation_fields"] || %{} + accepted_by: params["accepted_by"] || "system", + accepted_plan_id: params["accepted_plan_id"] } end @@ -166,9 +165,6 @@ defmodule PolicyServiceWeb.PolicyController do {:ok, updated} = PolicyQueries.get_by_application_id(org_id, application_id) conn |> put_status(:ok) |> json(%{data: policy_detail(updated)}) - {:error, :quote_not_found} -> - conn |> put_status(:not_found) |> json(%{error: "quote not found"}) - {:error, :plan_not_found} -> conn |> put_status(:not_found) |> json(%{error: "plan not found"}) @@ -192,7 +188,7 @@ defmodule PolicyServiceWeb.PolicyController do status: p.status, applicant_info: p.applicant_info, policy_details: p.policy_details, - policy_number: p.policy_number, + provider_policy_number: p.provider_policy_number, submitted_at: p.submitted_at } end @@ -208,13 +204,9 @@ defmodule PolicyServiceWeb.PolicyController do policy_details: p.policy_details, selected_providers: p.selected_providers, quotes: p.quotes, - accepted_quote_id: p.accepted_quote_id, accepted_plan_id: p.accepted_plan_id, - accepted_provider_id: p.accepted_provider_id, - accepted_at: p.accepted_at, - solicitation_id: p.solicitation_id, - solicitation_s3_key: p.solicitation_s3_key, - policy_number: p.policy_number, + accepted_by: p.accepted_by, + provider_policy_number: p.provider_policy_number, premium: p.premium, effective_date: p.effective_date, expiry_date: p.expiry_date, diff --git a/lib/policy_service_web/schemas/policy.ex b/lib/policy_service_web/schemas/policy.ex index fa53b7a..d1fa850 100644 --- a/lib/policy_service_web/schemas/policy.ex +++ b/lib/policy_service_web/schemas/policy.ex @@ -227,16 +227,10 @@ defmodule PolicyServiceWeb.Schemas.Policy do OpenApiSpex.schema(%{ title: "AcceptQuoteRequest", type: :object, - required: [:quote_id, :plan_id], + required: [:accepted_plan_id], properties: %{ quote_id: %Schema{type: :string}, - plan_id: %Schema{type: :string}, - solicitation_fields: %Schema{ - type: :object, - additionalProperties: %Schema{type: :string}, - description: "Optional flat map of AcroForm field names to values", - nullable: true - } + plan_id: %Schema{type: :string} } }) end @@ -266,7 +260,6 @@ defmodule PolicyServiceWeb.Schemas.Policy do type: :object, properties: %{ download_url: %Schema{type: :string}, - s3_key: %Schema{type: :string}, version: %Schema{type: :integer} } }) @@ -283,11 +276,11 @@ defmodule PolicyServiceWeb.Schemas.Policy do policy_type: %Schema{type: :string, enum: ["car", "life", "fire"]}, status: %Schema{ type: :string, - enum: ["quote_requested", "quotes_received", "solicitation_sent", "issued"] + enum: ["quote_requested", "quotes_received", "awaiting_policy", "issued"] }, applicant_info: ApplicantInfo, policy_details: PolicyDetails, - policy_number: %Schema{type: :string, nullable: true}, + provider_policy_number: %Schema{type: :string, nullable: true}, submitted_at: %Schema{type: :string, format: :"date-time"} } }) @@ -306,19 +299,15 @@ defmodule PolicyServiceWeb.Schemas.Policy do policy_type: %Schema{type: :string, enum: ["car", "life", "fire"]}, status: %Schema{ type: :string, - enum: ["quote_requested", "quotes_received", "solicitation_sent", "issued"] + enum: ["quote_requested", "quotes_received", "awaiting_policy", "issued"] }, applicant_info: ApplicantInfo, policy_details: PolicyDetails, selected_providers: %Schema{type: :array, items: %Schema{type: :string}}, quotes: %Schema{type: :object, additionalProperties: QuoteData}, - accepted_quote_id: %Schema{type: :string, nullable: true}, accepted_plan_id: %Schema{type: :string, nullable: true}, - accepted_provider_id: %Schema{type: :string, nullable: true}, - accepted_at: %Schema{type: :string, format: :"date-time", nullable: true}, - solicitation_id: %Schema{type: :string, nullable: true}, - solicitation_s3_key: %Schema{type: :string, nullable: true}, - policy_number: %Schema{type: :string, nullable: true}, + accepted_by: %Schema{type: :string, nullable: true}, + provider_policy_number: %Schema{type: :string, nullable: true}, premium: %Schema{type: :number, nullable: true}, effective_date: %Schema{type: :string, format: :date, nullable: true}, expiry_date: %Schema{type: :string, format: :date, nullable: true}, diff --git a/mix.exs b/mix.exs index d65bb19..17891b3 100644 --- a/mix.exs +++ b/mix.exs @@ -61,7 +61,8 @@ defmodule PolicyService.MixProject do {:cors_plug, "~> 3.0"}, {:flop, "~> 0.26"}, {:req, "~> 0.5"}, - {:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false} + {:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false}, + {:typedstruct, "~> 0.5"} ] end diff --git a/mix.lock b/mix.lock index f296d37..21c97f6 100644 --- a/mix.lock +++ b/mix.lock @@ -45,6 +45,10 @@ "telemetry_registry": {:hex, :telemetry_registry, "0.3.2", "701576890320be6428189bff963e865e8f23e0ff3615eade8f78662be0fc003c", [:mix, :rebar3], [{:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e7ed191eb1d115a3034af8e1e35e4e63d5348851d556646d46ca3d1b4e16bab9"}, "thoas": {:hex, :thoas, "1.2.1", "19a25f31177a17e74004d4840f66d791d4298c5738790fa2cc73731eb911f195", [:rebar3], [], "hexpm", "e38697edffd6e91bd12cea41b155115282630075c2a727e7a6b2947f5408b86a"}, "thousand_island": {:hex, :thousand_island, "1.4.3", "2158209580f633be38d43ec4e3ce0a01079592b9657afff9080d5d8ca149a3af", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6e4ce09b0fd761a58594d02814d40f77daff460c48a7354a15ab353bb998ea0b"}, + "typed_struct": {:hex, :typed_struct, "0.3.0", "939789e3c1dca39d7170c87f729127469d1315dcf99fee8e152bb774b17e7ff7", [:mix], [], "hexpm", "c50bd5c3a61fe4e198a8504f939be3d3c85903b382bde4865579bc23111d1b6d"}, + "typed_struct_ctor": {:hex, :typed_struct_ctor, "0.1.2", "00cc745439e99047615bb0700b43652311c199043293c13335151873505c5d01", [:mix], [{:ecto, "~> 3.10", [hex: :ecto, repo: "hexpm", optional: false]}, {:typed_struct_ecto_changeset, "~> 1.0.0", [hex: :typed_struct_ecto_changeset, repo: "hexpm", optional: false]}, {:typedstruct, "~> 0.5.2", [hex: :typedstruct, repo: "hexpm", optional: false]}], "hexpm", "79695303f7402f1a5b92e5914446014020b234bbfa1fccc664bacdf47101567f"}, + "typed_struct_ecto_changeset": {:hex, :typed_struct_ecto_changeset, "1.0.0", "40b6946074eabef74b44a6c55c79bbbcfda1abff9f82bd6fcbb738931937fa8f", [:mix], [], "hexpm", "9dccc15467402a75749907b7d07441638e92f45a2460cb068f0269d82bbc7a4e"}, + "typedstruct": {:hex, :typedstruct, "0.5.4", "d1d33d58460a74f413e9c26d55e66fd633abd8ac0fb12639add9a11a60a0462a", [:make, :mix], [], "hexpm", "ffaef36d5dbaebdbf4ed07f7fb2ebd1037b2c1f757db6fb8e7bcbbfabbe608d8"}, "websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"}, "websock_adapter": {:hex, :websock_adapter, "0.5.9", "43dc3ba6d89ef5dec5b1d0a39698436a1e856d000d84bf31a3149862b01a287f", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "5534d5c9adad3c18a0f58a9371220d75a803bf0b9a3d87e6fe072faaeed76a08"}, } diff --git a/priv/repo/migrations/20260310213733_create_car_policies.exs b/priv/repo/migrations/20260310213733_create_car_policies.exs index 989bfd7..02eb6b6 100644 --- a/priv/repo/migrations/20260310213733_create_car_policies.exs +++ b/priv/repo/migrations/20260310213733_create_car_policies.exs @@ -20,22 +20,15 @@ defmodule PolicyService.Repo.Migrations.CreatePolicyApplications do add :selected_providers, {:array, :string}, default: [] add :quotes, :map, default: %{} - # Accepted plan - add :accepted_quote_id, :string - add :accepted_plan_id, :string - add :accepted_provider_id, :string - add :accepted_by, :string - add :accepted_at, :utc_datetime_usec + # Accepted plan + add :accepted_plan_id, :string + add :accepted_by, :string - # Solicitation - add :solicitation_id, :string - add :solicitation_s3_key, :string - - # Issued policy - add :policy_number, :string - add :premium, :decimal - add :effective_date, :date - add :expiry_date, :date + # Issued policy + add :provider_policy_number, :string + add :premium, :decimal + add :effective_date, :date + add :expiry_date, :date # Status + timestamps add :status, :string, null: false