Compare commits
2 commits
470c805880
...
bec350e9f2
Author | SHA1 | Date | |
---|---|---|---|
bec350e9f2 | |||
16328d3840 |
2 changed files with 13 additions and 16 deletions
|
@ -71,9 +71,12 @@ class ItemsController < ApplicationController
|
|||
@basic_colored_pet_types_by_species_id = PetType.special_color_or_basic(@item.special_color).
|
||||
includes_child_translations.group_by(&:species)
|
||||
|
||||
trading_closet_hangers = @item.closet_hangers.trading.newest.
|
||||
user_is_active.includes(:user)
|
||||
|
||||
@trading_closet_hangers_by_owned = {
|
||||
true => @item.closet_hangers.owned_trading.newest.includes(:user),
|
||||
false => @item.closet_hangers.wanted_trading.newest.includes(:user)
|
||||
true => trading_closet_hangers.filter { |c| c.owned? },
|
||||
false => trading_closet_hangers.filter { |c| c.wanted? },
|
||||
}
|
||||
|
||||
if user_signed_in?
|
||||
|
|
|
@ -46,20 +46,10 @@ class ClosetHanger < ApplicationRecord
|
|||
scope :newest, -> { order(arel_table[:created_at].desc) }
|
||||
scope :owned_before_wanted, -> { order(arel_table[:owned].desc) }
|
||||
scope :unlisted, -> { where(:list_id => nil) }
|
||||
|
||||
{:owned => true, :wanted => false}.each do |name, owned|
|
||||
scope "#{name}_trading", -> {
|
||||
joins(:user).includes(:list).
|
||||
where(:owned => owned).
|
||||
where((
|
||||
arel_table[:list_id].eq(nil).and(
|
||||
User.arel_table["#{name}_closet_hangers_visibility"].gteq(ClosetVisibility[:trading].id)
|
||||
)
|
||||
).or(
|
||||
ClosetList.arel_table[:visibility].gteq(ClosetVisibility[:trading].id)
|
||||
))
|
||||
scope :user_is_active, -> {
|
||||
u = User.arel_table
|
||||
joins(:user).where(u[:last_trade_activity_at].gteq(6.months.ago))
|
||||
}
|
||||
end
|
||||
|
||||
before_validation :merge_quantities, :set_owned_by_list
|
||||
|
||||
|
@ -74,6 +64,10 @@ class ClosetHanger < ApplicationRecord
|
|||
possibly_null_closet_list.trading?
|
||||
end
|
||||
|
||||
def wanted?
|
||||
!owned?
|
||||
end
|
||||
|
||||
def possibly_null_list_id=(list_id_or_owned)
|
||||
if list_id_or_owned.to_s == 'true' || list_id_or_owned.to_s == 'false'
|
||||
self.list_id = nil
|
||||
|
|
Loading…
Reference in a new issue