This commit is contained in:
Ondřej 2024-08-09 14:37:12 +02:00
parent 7df19883b1
commit c9791acff8

View file

@ -25,10 +25,16 @@ defmodule ChoreTracker.Chores do
end end
def update_chore(%Chore{} = chore, attrs) do def update_chore(%Chore{} = chore, attrs) do
changeset = change_chore(chore, attrs)
Ecto.Multi.new() Ecto.Multi.new()
|> Ecto.Multi.update(:chore, change_chore(chore, attrs)) |> Ecto.Multi.update(:chore, changeset)
|> Ecto.Multi.run(:update_next_assignee, fn _repo, %{chore: chore} -> |> Ecto.Multi.run(:update_next_assignee, fn _repo, %{chore: chore} ->
if Ecto.Changeset.changed?(changeset, :assignees) do
save_next_chore_assignee(chore) save_next_chore_assignee(chore)
else
{:ok, chore}
end
end) end)
|> Repo.transaction() |> Repo.transaction()
end end