partition by org_id and add auth
All checks were successful
Build and Publish / build-release (push) Successful in 3m7s
All checks were successful
Build and Publish / build-release (push) Successful in 3m7s
This commit is contained in:
@@ -7,10 +7,15 @@ defmodule CustomerService.Projectors.Customer do
|
||||
|
||||
alias CustomerService.Events
|
||||
alias CustomerService.Projections.Customer
|
||||
alias CustomerService.Aggregates.CustomerId
|
||||
|
||||
project(%Events.CustomerCreated{} = event, fn multi ->
|
||||
%CustomerService.Aggregates.CustomerId{org_id: org_id, customer_id: customer_id} = event.id
|
||||
|
||||
Ecto.Multi.insert(multi, :customer, %Customer{
|
||||
id: event.id,
|
||||
id: CustomerId.to_string(event.id),
|
||||
org_id: org_id,
|
||||
customer_id: customer_id,
|
||||
customer_type: "individual",
|
||||
first_name: event.first_name,
|
||||
last_name: event.last_name,
|
||||
@@ -34,8 +39,12 @@ defmodule CustomerService.Projectors.Customer do
|
||||
end
|
||||
|
||||
project(%Events.CorporateCustomerCreated{} = e, _meta, fn multi ->
|
||||
%CustomerService.Aggregates.CustomerId{org_id: org_id, customer_id: customer_id} = e.id
|
||||
|
||||
Ecto.Multi.insert(multi, :customer, %Customer{
|
||||
id: e.id,
|
||||
id: CustomerId.to_string(e.id),
|
||||
org_id: org_id,
|
||||
customer_id: customer_id,
|
||||
customer_type: "corporate",
|
||||
legal_name: e.legal_name,
|
||||
commercial_name: e.commercial_name,
|
||||
@@ -49,7 +58,9 @@ defmodule CustomerService.Projectors.Customer do
|
||||
end)
|
||||
|
||||
project(%Events.CustomerUpdated{} = e, _meta, fn multi ->
|
||||
Ecto.Multi.update_all(multi, :customer, from(c in Customer, where: c.id == ^e.id),
|
||||
composite_id = CustomerId.to_string(e.id)
|
||||
|
||||
Ecto.Multi.update_all(multi, :customer, from(c in Customer, where: c.id == ^composite_id),
|
||||
set: [
|
||||
first_name: e.first_name,
|
||||
last_name: e.last_name,
|
||||
@@ -64,7 +75,9 @@ defmodule CustomerService.Projectors.Customer do
|
||||
end)
|
||||
|
||||
project(%Events.CorporateCustomerUpdated{} = e, _meta, fn multi ->
|
||||
Ecto.Multi.update_all(multi, :customer, from(c in Customer, where: c.id == ^e.id),
|
||||
composite_id = CustomerId.to_string(e.id)
|
||||
|
||||
Ecto.Multi.update_all(multi, :customer, from(c in Customer, where: c.id == ^composite_id),
|
||||
set: [
|
||||
legal_name: e.legal_name,
|
||||
commercial_name: e.commercial_name,
|
||||
|
||||
Reference in New Issue
Block a user