Skip to content

Commit

Permalink
fix: remove unnecessary function
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Dec 2, 2023
1 parent a9b8bf2 commit 5fa6b70
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions lib/store/inventory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ 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: [:user, :products])

case order do
%Order{} ->
Expand All @@ -355,13 +355,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"])

Expand Down Expand Up @@ -606,8 +599,7 @@ defmodule Store.Inventory do

def get_order_draft_by_id(user_id, opts) when is_list(opts) do
Order
|> where(user_id: ^user_id)
|> where(status: :draft)
|> where(user_id: ^user_id, status: :draft)
|> Repo.one()
|> apply_filters(opts)
end
Expand Down

0 comments on commit 5fa6b70

Please sign in to comment.