Class: Customer
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Customer
- Defined in:
- app/models/customer.rb
Instance Method Summary collapse
- #as_json ⇒ Object
- #as_json2 ⇒ Object
-
#get_rating_information(agent_id) ⇒ Object
Get rating information.
-
#name ⇒ Object
end.
Instance Method Details
#as_json ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/customer.rb', line 31 def as_json user = User.find_by(id: self.user_id) { authentication_token: user.authentication_token, email: user.email, customer_id: self.id, phone_number: self.phone_number, phone_verified: self.phone_verified, first_name: self.first_name, last_name: self.last_name, inital_contact: self.inital_contact, language_1: self.preferred_language_id_1, language_2: self.preferred_language_id_2 } end |
#as_json2 ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/customer.rb', line 47 def as_json2 user = User.find_by(id: self.user_id) { authentication_token: user.authentication_token, email: user.email, customer_id: self.id, phone_number: self.phone_number, phone_verified: self.phone_verified, first_name: self.first_name, last_name: self.last_name, inital_contact: self.inital_contact, language_1: self.language1.try(:name), language_2: self.language2.try(:name), } end |
#get_rating_information(agent_id) ⇒ Object
Get rating information
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/customer.rb', line 64 def (agent_id) = Rating.where(agent_id: agent_id) numCustomerRates = .distinct.count(:customer_id) avgAll = .average('rate').to_f avgCategory = .joins(:rating_question).group('category').average('rate').map{|category, rate| {category: category, rate: rate}} = .where(customer_id: self.id) avgQuestion = .group('rating_question_id').average('rate').map{|question, rate| {question: question, rate: rate}} = .joins(:rating_question).select('category, CAST(MAX(ratings.updated_at) as date) as date').group('category') {numCustomerRates: numCustomerRates, avgAllRates: avgAll, avgCategory: avgCategory, avgQuestion: avgQuestion, rating_date: } end |
#name ⇒ Object
end
25 26 27 28 29 |
# File 'app/models/customer.rb', line 25 def name if first_name.present? && last_name.present? "#{first_name} #{last_name}" end end |