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,
|
||||
|
||||
@@ -7,10 +7,15 @@ defmodule CustomerService.Projectors.QuickLead do
|
||||
|
||||
alias CustomerService.Events
|
||||
alias CustomerService.Projections.QuickLead
|
||||
alias CustomerService.Aggregates.LeadId
|
||||
|
||||
project(%Events.QuickLeadCreated{} = event, fn multi ->
|
||||
%CustomerService.Aggregates.LeadId{org_id: org_id, lead_id: lead_id} = event.id
|
||||
|
||||
Ecto.Multi.insert(multi, :quick_lead, %QuickLead{
|
||||
id: event.id,
|
||||
id: LeadId.to_string(event.id),
|
||||
org_id: org_id,
|
||||
lead_id: lead_id,
|
||||
name: event.name,
|
||||
email: event.email,
|
||||
phone: event.phone,
|
||||
@@ -33,7 +38,9 @@ defmodule CustomerService.Projectors.QuickLead do
|
||||
end)
|
||||
|
||||
project(%Events.QuickLeadUpdated{} = event, _meta, fn multi ->
|
||||
Ecto.Multi.update_all(multi, :quick_lead, from(q in QuickLead, where: q.id == ^event.id),
|
||||
composite_id = LeadId.to_string(event.id)
|
||||
|
||||
Ecto.Multi.update_all(multi, :quick_lead, from(q in QuickLead, where: q.id == ^composite_id),
|
||||
set: [
|
||||
name: event.name,
|
||||
email: event.email,
|
||||
@@ -48,7 +55,9 @@ defmodule CustomerService.Projectors.QuickLead do
|
||||
end)
|
||||
|
||||
project(%Events.LeadStatusUpdated{} = event, _meta, fn multi ->
|
||||
Ecto.Multi.update_all(multi, :quick_lead, from(q in QuickLead, where: q.id == ^event.id),
|
||||
composite_id = LeadId.to_string(event.id)
|
||||
|
||||
Ecto.Multi.update_all(multi, :quick_lead, from(q in QuickLead, where: q.id == ^composite_id),
|
||||
set: [
|
||||
status: to_string(event.status)
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user