Skip to content

Commit

Permalink
fix stocks.rb: task #7
Browse files Browse the repository at this point in the history
 filters must deal with nil and check blank since it comes from the params controller
  • Loading branch information
Pauloparakleto committed Dec 23, 2023
1 parent 786c4a0 commit 7ba359e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/models/stock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ class Stock < ApplicationRecord

delegate :active, :bling_id, :name, to: :product

def self.filter_by_total_balance_situation(balance_situation = :all)
return all if balance_situation == :all
def self.filter_by_total_balance_situation(balance_situation = nil)
return all if balance_situation.blank?

balance_situation_parser = { 1 => '>', -1 => '<', 0 => '=' }
balance_situation = balance_situation_parser[balance_situation]
balance_situation = balance_situation_parser[balance_situation.to_i]
where("total_balance #{balance_situation} ?", 0)
end

def self.filter_by_status(status_number = :all)
return all if status_number == :all
def self.filter_by_status(status_number = nil)
return all if status_number.blank?

joins(:product).where(product: { active: status_number })
end
Expand Down

0 comments on commit 7ba359e

Please sign in to comment.