Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Tenant < ApplicationRecord
- has_many :users
- has_many :chat_messages
- end
- class User < ApplicationRecord
- belongs_to :organization
- has_many :authored_conversations, class_name: 'Conversation', :as => :author
- has_many :chat_messages, as: :user, dependent: :nullify
- has_many :received_conversations, :as => :receiver, class_name: 'Conversation'
- def conversations
- authored_conversations + received_conversations
- end
- def response_time
- # calculate the user's average response time
- end
- end
- class ReportGenerator
- def initialize(org_id)
- @organization = Organization.find org_id
- end
- def generate_report
- report = Report.generate(@organization)
- ReportMailer.new_report(report).deliver_later
- end
- end
- class ReportMailer < ApplicationMailer
- default from: ENV["DEFAULT_MAILER_FROM"],
- template_path: 'mailers/chat_message_mailer'
- def new_message(report, recipient)
- @report = report
- @recipient = recipient
- @subject = "Monthly report for #{report.created_at}"
- @greeting = "Hi, #{recipient.name}"
- @body = @report.body
- mail(to: @recipient.email, subject: @subject)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement