psanchezp

User score

...@@ -26,6 +26,8 @@ class User < ApplicationRecord ...@@ -26,6 +26,8 @@ class User < ApplicationRecord
26 26
27 before_save :encrypt_password 27 before_save :encrypt_password
28 28
29 + has_many :bets, inverse_of: :user
30 +
29 has_and_belongs_to_many :roles, inverse_of: :users, 31 has_and_belongs_to_many :roles, inverse_of: :users,
30 class_name: 'HeimdallEngine::Role', 32 class_name: 'HeimdallEngine::Role',
31 join_table: 'users_roles', 33 join_table: 'users_roles',
...@@ -33,6 +35,10 @@ class User < ApplicationRecord ...@@ -33,6 +35,10 @@ class User < ApplicationRecord
33 association_foreign_key: "role_id" 35 association_foreign_key: "role_id"
34 36
35 37
38 + def user_score
39 + bets.active.sum :points
40 + end
41 +
36 def encrypt_password 42 def encrypt_password
37 return unless password.present? 43 return unless password.present?
38 self.password_salt = BCrypt::Engine.generate_salt.force_encoding('UTF-8') 44 self.password_salt = BCrypt::Engine.generate_salt.force_encoding('UTF-8')
......