diff --git a/lib/chore_tracker/accounts.ex b/lib/chore_tracker/accounts.ex index ed4b6ca..6c86c7f 100644 --- a/lib/chore_tracker/accounts.ex +++ b/lib/chore_tracker/accounts.ex @@ -18,10 +18,6 @@ defmodule ChoreTracker.Accounts do Repo.all(from user in User, where: user.id in ^ids) end - def get_user!(id) do - Repo.get!(User, id) - end - ## Database getters @doc """ diff --git a/lib/chore_tracker/chores.ex b/lib/chore_tracker/chores.ex index d511acb..db539ef 100644 --- a/lib/chore_tracker/chores.ex +++ b/lib/chore_tracker/chores.ex @@ -141,9 +141,9 @@ defmodule ChoreTracker.Chores do """ def get_chore_log!(id), do: Repo.get!(ChoreLog, id) - def get_last_log_for_assignee(%User{} = user) do + def get_last_chore_log_for_assignee(%Chore{} = chore, %User{} = user) do from(log in ChoreLog, - where: log.user_id == ^user.id, + where: log.chore_id == ^chore.id and log.user_id == ^user.id, order_by: [desc: :inserted_at], limit: 1 ) @@ -327,7 +327,7 @@ defmodule ChoreTracker.Chores do def next_chore_assignee(%Chore{} = chore) do chore.assignees - |> Enum.map(&{&1, get_last_log_for_assignee(&1)}) + |> Enum.map(&{&1, get_last_chore_log_for_assignee(chore, &1)}) |> Enum.sort_by( fn {_assignee, log} -> case log do