Class: Unit

Inherits:
ApplicationRecord show all
Defined in:
app/models/unit.rb

Class Method Summary collapse

Class Method Details

.get_inspectable_units(property_id) ⇒ Object



26
27
28
29
30
# File 'app/models/unit.rb', line 26

def self.get_inspectable_units(property_id)
  units = Unit.where(property_id: property_id).where("properties->>'uninspectable' = ? OR properties->>'uninspectable' IS NULL", 'None')
  sorted_units = ApplicationHelper.key_merge_sort(units, 'id', 0, 1)
  sorted_units
end

.get_property_units(property_id) ⇒ Object



21
22
23
24
25
# File 'app/models/unit.rb', line 21

def self.get_property_units(property_id)
  units = Unit.where(property_id: property_id)
  sorted_units = ApplicationHelper.key_merge_sort(units, 'id', 0, 1)
  sorted_units
end

.search(property_id) ⇒ Object



13
14
15
16
17
18
19
# File 'app/models/unit.rb', line 13

def self.search(property_id)
  if property_id
    where('property_id = ?', property_id.to_s)
  else
    all
  end
end

.total_inspectable_units(property_id) ⇒ Object



31
32
33
# File 'app/models/unit.rb', line 31

def self.total_inspectable_units(property_id)
  Unit.where(property_id: property_id).where("properties->>'uninspectable' = ? OR properties->>'uninspectable' IS NULL", 'None').count
end