diff --git a/lib/store/inventory.ex b/lib/store/inventory.ex index 8ebb9fb..4882d78 100644 --- a/lib/store/inventory.ex +++ b/lib/store/inventory.ex @@ -344,7 +344,8 @@ defmodule Store.Inventory do alias Store.Accounts.User def purchase(%User{} = user, %Product{} = product, product_params) do - order = get_user_draft_order(user) + order = get_order_draft_by_id(user.id, preloads: []) + case order do %Order{} -> @@ -355,13 +356,6 @@ defmodule Store.Inventory do end end - defp get_user_draft_order(user) do - Order - |> where(user_id: ^user.id, status: :draft) - |> Repo.one() - |> Repo.preload([:user, :products]) - end - defp handle_existing_order(order, product, product_params) do quantity = String.to_integer(product_params["quantity"])