generica/app/models/admin/user.rb in cloudrider-0.3.21 vs generica/app/models/admin/user.rb in cloudrider-0.3.22

- old
+ new

@@ -33,10 +33,24 @@ has_many :products, class_name: 'Apiv1::Product', through: :product_relationships + has_many :raw_contacts, + class_name: 'Apiv1::UserContact', + foreign_key: 'user_id' + + has_many :contacts, + -> { order_by_primality }, + class_name: 'Apiv1::UserContact', + foreign_key: 'user_id' + + has_one :primary_contact, + -> { is_primary.order_by_primality }, + class_name: 'Apiv1::UserContact', + foreign_key: 'user_id' + has_many :offers, -> { order "#{Apiv1::OfferMessage.table_name}.created_at desc" }, through: :products, class_name: 'Apiv1::OfferMessage' @@ -47,11 +61,11 @@ user_rank: user_rank, company_name: company_name, phone_number: phone_number, address: address, about_me: about_me - } + }.merge _primary_contact_hash end def admin? user_rank.to_s == "admin" end @@ -60,7 +74,12 @@ update user_rank: "admin" end def owns?(product) product_relationships.exists?(product_id: product.id) + end + + private + def _primary_contact_hash + primary_contact.try(:to_user_hash) || {} end end