Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. class Tenant < ApplicationRecord
  2.  
  3. has_many :users
  4. has_many :chat_messages
  5.  
  6. end
  7.  
  8. class User < ApplicationRecord
  9.  
  10. belongs_to :organization
  11. has_many :authored_conversations, class_name: 'Conversation', :as => :author
  12. has_many :chat_messages, as: :user, dependent: :nullify
  13. has_many :received_conversations, :as => :receiver, class_name: 'Conversation'
  14.  
  15. def conversations
  16. authored_conversations + received_conversations
  17. end
  18.  
  19. def response_time
  20. # calculate the user's average response time
  21. end
  22.  
  23. end
  24.  
  25. class ReportGenerator
  26.  
  27. def initialize(org_id)
  28. @organization = Organization.find org_id
  29. end
  30.  
  31. def generate_report
  32. report = Report.generate(@organization)
  33. ReportMailer.new_report(report).deliver_later
  34. end
  35.  
  36. end
  37.  
  38. class ReportMailer < ApplicationMailer
  39. default from: ENV["DEFAULT_MAILER_FROM"],
  40. template_path: 'mailers/chat_message_mailer'
  41.  
  42. def new_message(report, recipient)
  43. @report = report
  44. @recipient = recipient
  45. @subject = "Monthly report for #{report.created_at}"
  46. @greeting = "Hi, #{recipient.name}"
  47. @body = @report.body
  48. mail(to: @recipient.email, subject: @subject)
  49. end
  50.  
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement