properly decode policy id
Some checks failed
Build and Publish / build-release (push) Failing after 35s
Some checks failed
Build and Publish / build-release (push) Failing after 35s
This commit is contained in:
@@ -43,6 +43,10 @@ defmodule PolicyService.Aggregates.PolicyId do
|
||||
end
|
||||
|
||||
defimpl Commanded.Serialization.JsonDecoder do
|
||||
def decode(%{org_id: org_id, policy_type: policy_type, application_id: application_id}) do
|
||||
PolicyService.Aggregates.PolicyId.new(org_id, policy_type, application_id)
|
||||
end
|
||||
|
||||
def decode(id), do: id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
defmodule PolicyService.Events.Policy do
|
||||
@moduledoc """
|
||||
Policy domain events.
|
||||
Contains helpers for common event functionality.
|
||||
"""
|
||||
|
||||
alias PolicyService.Aggregates.PolicyId
|
||||
|
||||
defmacro __using__(_opts) do
|
||||
quote do
|
||||
defimpl Commanded.Serialization.JsonDecoder do
|
||||
def decode(%{id: %{org_id: org_id, policy_type: policy_type, application_id: application_id}} = event) do
|
||||
%{event | id: PolicyId.new(org_id, policy_type, application_id)}
|
||||
end
|
||||
|
||||
def decode(event), do: event
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defmodule PolicyApplicationSubmitted do
|
||||
use PolicyService.Events.Policy
|
||||
@derive Jason.Encoder
|
||||
defstruct [
|
||||
:id,
|
||||
@@ -12,6 +32,7 @@ defmodule PolicyService.Events.Policy do
|
||||
end
|
||||
|
||||
defmodule QuoteRequestSent do
|
||||
use PolicyService.Events.Policy
|
||||
@derive Jason.Encoder
|
||||
defstruct [
|
||||
:id,
|
||||
@@ -24,6 +45,7 @@ defmodule PolicyService.Events.Policy do
|
||||
end
|
||||
|
||||
defmodule ProviderQuoteReceived do
|
||||
use PolicyService.Events.Policy
|
||||
@derive Jason.Encoder
|
||||
defstruct [
|
||||
:id,
|
||||
@@ -39,11 +61,13 @@ defmodule PolicyService.Events.Policy do
|
||||
end
|
||||
|
||||
defmodule AllQuotesReceived do
|
||||
use PolicyService.Events.Policy
|
||||
@derive Jason.Encoder
|
||||
defstruct [:id, :quote_count]
|
||||
end
|
||||
|
||||
defmodule QuoteAccepted do
|
||||
use PolicyService.Events.Policy
|
||||
@derive Jason.Encoder
|
||||
defstruct [
|
||||
:id,
|
||||
@@ -56,6 +80,7 @@ defmodule PolicyService.Events.Policy do
|
||||
end
|
||||
|
||||
defmodule SolicitationSent do
|
||||
use PolicyService.Events.Policy
|
||||
@derive Jason.Encoder
|
||||
defstruct [
|
||||
:id,
|
||||
@@ -68,6 +93,7 @@ defmodule PolicyService.Events.Policy do
|
||||
end
|
||||
|
||||
defmodule PolicyIssued do
|
||||
use PolicyService.Events.Policy
|
||||
@derive Jason.Encoder
|
||||
defstruct [
|
||||
:id,
|
||||
|
||||
@@ -19,14 +19,12 @@ defmodule PolicyService.Projectors.PolicyProjector do
|
||||
import Ecto.Query
|
||||
|
||||
project(%PolicyApplicationSubmitted{} = e, _meta, fn multi ->
|
||||
%{policy_type: policy_type, application_id: application_id, org_id: org_id} = e.id
|
||||
|
||||
Ecto.Multi.insert(multi, :policy_application, %PolicyApplication{
|
||||
id: to_string(PolicyId.new(org_id, policy_type, application_id)),
|
||||
application_id: application_id,
|
||||
org_id: org_id,
|
||||
id: to_string(e.id),
|
||||
application_id: e.id.application_id,
|
||||
org_id: e.id.org_id,
|
||||
submitted_by: e.submitted_by,
|
||||
policy_type: policy_type,
|
||||
policy_type: e.id.policy_type,
|
||||
applicant_info: atomize(e.applicant_info),
|
||||
policy_details: atomize(e.policy_details),
|
||||
selected_providers: Enum.map(e.selected_providers, & &1["provider_id"]),
|
||||
|
||||
Reference in New Issue
Block a user