Skip to content

Commit

Permalink
Check amount in add to order command (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
verarojman authored and leio10 committed Jul 22, 2021
1 parent d063014 commit 60b9e79
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(current_order, project, current_user)
# Returns nothing.
def call
transaction do
return broadcast(:invalid) if voting_not_enabled? || order.checked_out?
return broadcast(:invalid) if voting_not_enabled? || order.checked_out? || exceeds_budget?

add_line_item
broadcast(:ok, order)
Expand All @@ -44,6 +44,10 @@ def add_line_item
end
end

def exceeds_budget?
order.allocation_for(project) + order.total > project.budget.total_budget
end

def voting_not_enabled?
project.component.current_settings.votes != "enabled"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def create
end

on(:invalid) do
render nothing: true, status: :unprocessable_entity
format.js { render "update_budget", status: :unprocessable_entity }
end
end
end
Expand All @@ -35,7 +35,7 @@ def destroy
end

on(:invalid) do
render nothing: true, status: :unprocessable_entity
format.js { render "update_budget", status: :unprocessable_entity }
end
end
end
Expand Down

0 comments on commit 60b9e79

Please sign in to comment.