mirror of
https://codeberg.org/JasterV/spazio-solazzo.git
synced 2026-04-26 18:20:03 +00:00
49 lines
1.3 KiB
Elixir
49 lines
1.3 KiB
Elixir
defmodule SpazioSolazzo.BookingSystem.Booking.EmailWorker do
|
|
@moduledoc """
|
|
Sends booking confirmation emails to customers and notification emails to administrators.
|
|
"""
|
|
|
|
use Oban.Worker, queue: :booking_email, max_attempts: 1
|
|
|
|
alias SpazioSolazzo.BookingSystem.Booking.Email
|
|
|
|
@impl Oban.Worker
|
|
def perform(%Oban.Job{
|
|
args: %{
|
|
"booking_id" => booking_id,
|
|
"customer_name" => customer_name,
|
|
"customer_email" => customer_email,
|
|
"customer_phone" => customer_phone,
|
|
"customer_comment" => customer_comment,
|
|
"date" => date,
|
|
"start_time" => start_time,
|
|
"end_time" => end_time
|
|
}
|
|
}) do
|
|
email_data = %{
|
|
booking_id: booking_id,
|
|
customer_name: customer_name,
|
|
customer_email: customer_email,
|
|
customer_phone: customer_phone,
|
|
customer_comment: customer_comment,
|
|
date: date,
|
|
start_time: start_time,
|
|
end_time: end_time,
|
|
admin_email: admin_email()
|
|
}
|
|
|
|
email_data
|
|
|> Email.customer_confirmation()
|
|
|> SpazioSolazzo.Mailer.deliver!()
|
|
|
|
email_data
|
|
|> Email.admin_notification()
|
|
|> SpazioSolazzo.Mailer.deliver!()
|
|
|
|
:ok
|
|
end
|
|
|
|
defp admin_email do
|
|
Application.get_env(:spazio_solazzo, :admin_email)
|
|
end
|
|
end
|