refactor some ugly code

This commit is contained in:
JasterV 2026-02-01 21:46:44 +01:00
parent 0f019615b2
commit 68422546ad
2 changed files with 19 additions and 27 deletions

View file

@ -16,16 +16,11 @@ defmodule SpazioSolazzo.Accounts.User.Changes.HandleBookingsOnAccountDeletion do
user = changeset.data
delete_history = Ash.Changeset.get_argument(changeset, :delete_history)
future_bookings =
Booking
|> Ash.Query.filter(
user_id == ^user.id and state in [:requested, :accepted] and date >= ^Date.utc_today()
)
|> Ash.read!()
Enum.each(future_bookings, fn booking ->
BookingSystem.cancel_booking!(booking, "Account deleted by user")
end)
Booking
|> Ash.Query.filter(
user_id == ^user.id and state in [:requested, :accepted] and date >= ^Date.utc_today()
)
|> BookingSystem.cancel_booking!("Account deleted by user")
if delete_history do
Booking

View file

@ -60,25 +60,22 @@ defmodule SpazioSolazzo.BookingSystem.Booking do
filter expr(state == :requested or state == :accepted)
prepare fn query, _ctx ->
query
|> then(fn q ->
case Ash.Query.get_argument(q, :space_id) do
nil -> q
space_id -> Ash.Query.filter(q, space_id == ^space_id)
query =
case Ash.Query.get_argument(query, :space_id) do
nil -> query
space_id -> Ash.Query.filter(query, space_id == ^space_id)
end
end)
|> then(fn q ->
case Ash.Query.get_argument(q, :email) do
nil -> q
email -> Ash.Query.filter(q, customer_email == ^email)
query =
case Ash.Query.get_argument(query, :email) do
nil -> query
email -> Ash.Query.filter(query, customer_email == ^email)
end
end)
|> then(fn q ->
case Ash.Query.get_argument(q, :date) do
nil -> q
date -> Ash.Query.filter(q, date == ^date)
end
end)
case Ash.Query.get_argument(query, :date) do
nil -> query
date -> Ash.Query.filter(query, date == ^date)
end
end
end