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
|
end
|
||||||
|
|
||||||
defimpl Commanded.Serialization.JsonDecoder do
|
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
|
def decode(id), do: id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,25 @@
|
|||||||
defmodule PolicyService.Events.Policy do
|
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
|
defmodule PolicyApplicationSubmitted do
|
||||||
|
use PolicyService.Events.Policy
|
||||||
@derive Jason.Encoder
|
@derive Jason.Encoder
|
||||||
defstruct [
|
defstruct [
|
||||||
:id,
|
:id,
|
||||||
@@ -12,6 +32,7 @@ defmodule PolicyService.Events.Policy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defmodule QuoteRequestSent do
|
defmodule QuoteRequestSent do
|
||||||
|
use PolicyService.Events.Policy
|
||||||
@derive Jason.Encoder
|
@derive Jason.Encoder
|
||||||
defstruct [
|
defstruct [
|
||||||
:id,
|
:id,
|
||||||
@@ -24,6 +45,7 @@ defmodule PolicyService.Events.Policy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defmodule ProviderQuoteReceived do
|
defmodule ProviderQuoteReceived do
|
||||||
|
use PolicyService.Events.Policy
|
||||||
@derive Jason.Encoder
|
@derive Jason.Encoder
|
||||||
defstruct [
|
defstruct [
|
||||||
:id,
|
:id,
|
||||||
@@ -39,11 +61,13 @@ defmodule PolicyService.Events.Policy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defmodule AllQuotesReceived do
|
defmodule AllQuotesReceived do
|
||||||
|
use PolicyService.Events.Policy
|
||||||
@derive Jason.Encoder
|
@derive Jason.Encoder
|
||||||
defstruct [:id, :quote_count]
|
defstruct [:id, :quote_count]
|
||||||
end
|
end
|
||||||
|
|
||||||
defmodule QuoteAccepted do
|
defmodule QuoteAccepted do
|
||||||
|
use PolicyService.Events.Policy
|
||||||
@derive Jason.Encoder
|
@derive Jason.Encoder
|
||||||
defstruct [
|
defstruct [
|
||||||
:id,
|
:id,
|
||||||
@@ -56,6 +80,7 @@ defmodule PolicyService.Events.Policy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defmodule SolicitationSent do
|
defmodule SolicitationSent do
|
||||||
|
use PolicyService.Events.Policy
|
||||||
@derive Jason.Encoder
|
@derive Jason.Encoder
|
||||||
defstruct [
|
defstruct [
|
||||||
:id,
|
:id,
|
||||||
@@ -68,6 +93,7 @@ defmodule PolicyService.Events.Policy do
|
|||||||
end
|
end
|
||||||
|
|
||||||
defmodule PolicyIssued do
|
defmodule PolicyIssued do
|
||||||
|
use PolicyService.Events.Policy
|
||||||
@derive Jason.Encoder
|
@derive Jason.Encoder
|
||||||
defstruct [
|
defstruct [
|
||||||
:id,
|
:id,
|
||||||
|
|||||||
@@ -19,14 +19,12 @@ defmodule PolicyService.Projectors.PolicyProjector do
|
|||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
project(%PolicyApplicationSubmitted{} = e, _meta, fn multi ->
|
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{
|
Ecto.Multi.insert(multi, :policy_application, %PolicyApplication{
|
||||||
id: to_string(PolicyId.new(org_id, policy_type, application_id)),
|
id: to_string(e.id),
|
||||||
application_id: application_id,
|
application_id: e.id.application_id,
|
||||||
org_id: org_id,
|
org_id: e.id.org_id,
|
||||||
submitted_by: e.submitted_by,
|
submitted_by: e.submitted_by,
|
||||||
policy_type: policy_type,
|
policy_type: e.id.policy_type,
|
||||||
applicant_info: atomize(e.applicant_info),
|
applicant_info: atomize(e.applicant_info),
|
||||||
policy_details: atomize(e.policy_details),
|
policy_details: atomize(e.policy_details),
|
||||||
selected_providers: Enum.map(e.selected_providers, & &1["provider_id"]),
|
selected_providers: Enum.map(e.selected_providers, & &1["provider_id"]),
|
||||||
|
|||||||
Reference in New Issue
Block a user