add quick leads
All checks were successful
Build and Publish / build-release (push) Successful in 2m13s

This commit is contained in:
2026-04-30 16:40:40 -05:00
parent 3a22776568
commit cfd810beba
20 changed files with 1054 additions and 11 deletions

View File

@@ -47,4 +47,34 @@ defmodule CustomerService.Projectors.Customer do
address: e.address
})
end)
project(%Events.CustomerUpdated{} = e, _meta, fn multi ->
Ecto.Multi.update_all(multi, :customer, from(c in Customer, where: c.id == ^e.id),
set: [
first_name: e.first_name,
last_name: e.last_name,
birth_date: parse_date(e.birth_date),
gender: e.gender,
email: e.email,
phone: e.phone,
address: e.address,
document_id: e.document_id
]
)
end)
project(%Events.CorporateCustomerUpdated{} = e, _meta, fn multi ->
Ecto.Multi.update_all(multi, :customer, from(c in Customer, where: c.id == ^e.id),
set: [
legal_name: e.legal_name,
commercial_name: e.commercial_name,
ruc: e.ruc,
legal_rep_name: e.legal_rep_name,
legal_rep_document_id: e.legal_rep_document_id,
email: e.email,
phone: e.phone,
address: e.address
]
)
end)
end

View File

@@ -0,0 +1,67 @@
defmodule CustomerService.Projectors.QuickLead do
use Commanded.Projections.Ecto,
application: CustomerService.CommandedApp,
repo: CustomerService.Repo,
name: "CustomerService.Projectors.QuickLead",
consistency: :strong
alias CustomerService.Events
alias CustomerService.Projections.QuickLead
project(%Events.QuickLeadCreated{} = event, fn multi ->
Ecto.Multi.insert(multi, :quick_lead, %QuickLead{
id: event.id,
name: event.name,
email: event.email,
phone: event.phone,
company_name: event.company_name,
status: to_string(event.status),
priority: to_string(event.priority),
source: to_string(event.source),
notes: event.notes,
assigned_to: event.assigned_to,
estimated_value: event.estimated_value,
expected_close_date: parse_date(event.expected_close_date),
status_history: [
%{
status: to_string(event.status),
updated_at: DateTime.utc_now(),
notes: "Lead created"
}
]
})
end)
project(%Events.QuickLeadUpdated{} = event, _meta, fn multi ->
Ecto.Multi.update_all(multi, :quick_lead, from(q in QuickLead, where: q.id == ^event.id),
set: [
name: event.name,
email: event.email,
phone: event.phone,
company_name: event.company_name,
notes: event.notes,
assigned_to: event.assigned_to,
estimated_value: event.estimated_value,
expected_close_date: parse_date(event.expected_close_date)
]
)
end)
project(%Events.LeadStatusUpdated{} = event, _meta, fn multi ->
Ecto.Multi.update_all(multi, :quick_lead, from(q in QuickLead, where: q.id == ^event.id),
set: [
status: to_string(event.status)
]
)
end)
defp parse_date(nil), do: nil
defp parse_date(%Date{} = d), do: d
defp parse_date(str) when is_binary(str) do
case Date.from_iso8601(str) do
{:ok, d} -> d
_ -> nil
end
end
end