class ExpertSessionView

Schema Information

Table name: expert_session_views

id                :integer          default(0), not null, primary key
user_id           :integer
fixxpert_id       :integer
last_notification :datetime
end_time          :datetime
company_id        :integer

Public Class Methods

billing_reminder() click to toggle source

send email notifications for completed session

# File app/models/expert_session_view.rb, line 19
def self.billing_reminder
  if Configurations::BalancedPayment.enabled?
    expert_sessions = where("
      end_time <= ? AND last_notification IS NULL
    ", Time.now - 2.hours)

    expert_sessions.each do |ts|
      begin
        invoice = ts.invoice
        invoice ||= ts.build_invoice(user_id: ts.user_id, fixxpert_id: ts.fixxpert_id)
        invoice.last_notification = Time.now.in_time_zone
        invoice.email_notifications += 1
        if invoice.save(validate: false)
          InvoiceMailer.delay(queue: :mailer).billing_reminder(expert_session.id)
        end
      rescue
        next
      end
    end
  end
end
pay_for_sessions() click to toggle source

pay fixxpert for completed session it not marked as 'not-occured' skip previous sessions

# File app/models/expert_session_view.rb, line 43
def self.pay_for_sessions
  if Configurations::BalancedPayment.enabled?
    expert_sessions = where("
      end_time <= ? ", Time.now - 24.hours)

    expert_sessions.each do |expert_session|
      begin
        puts "paying fixxpert"
        invoice = Invoice.find_by(invoiceable_id: expert_session.id)
        invoice.pay_fixxpert
      rescue
        next
      end
    end
  end
end
reminder_to_attend_session() click to toggle source

Send reminder to fixxpert to attend the session.

# File app/models/expert_session_view.rb, line 71
def self.reminder_to_attend_session
  expert_sessions = ExpertSession.where('old_session IS false and status = ? and start_time between ? and ? and not exists(select * from notification_statuses ns where ns.resource_id = expert_sessions.id and ns.resource_type = "ExpertSession" and ns.notification_type = "session_reminder")', 'c', Time.now.in_time_zone, Time.now.in_time_zone + 1.hours)
  expert_sessions.find_each do |expert_session|
    if expert_session.build_session_reminder(user_id: expert_session.user_id, sent_at: Time.now.in_time_zone).save
      ExpertSessionsMailer.delay(queue: :mailer).session_reminder_fixxpert(expert_session)
      ExpertSessionsMailer.delay(queue: :mailer).session_reminder_customer(expert_session)
    end
  end
end
reminder_to_confirm_session() click to toggle source

Send mail to fixxpert to confirm the session.(i.e. to accept request of expert session)

# File app/models/expert_session_view.rb, line 61
def self.reminder_to_confirm_session
  expert_sessions = ExpertSession.where('status IS NULL and old_session IS false and start_time between ? and ? and not exists(select * from notification_statuses ns where ns.resource_id = expert_sessions.id and ns.resource_type = "ExpertSession" and ns.notification_type = "confirmation_reminder")', Time.now.in_time_zone, Time.now.in_time_zone + 3.hours)
  expert_sessions.find_each do |expert_session|
    if expert_session.build_confirmation_reminder(user_id: expert_session.user_id, sent_at: Time.now.in_time_zone).save
      ExpertSessionsMailer.delay(queue: :mailer).confirmation_reminder_email_fixxpert(expert_session)
    end
  end
end
send_notification_for_unconfirmed_sessions() click to toggle source

Send mail to users for unconfirmed session.

# File app/models/expert_session_view.rb, line 82
def self.send_notification_for_unconfirmed_sessions
  ExpertSession.unnotified_expired_pending_sessions.find_each do |expert_session|
    expert_session.notification_sent_at = Time.now.in_time_zone
    if expert_session.save(validate: false)
      ExpertSessionsMailer.delay(queue: :mailer).passed_unconfirmed_session_email_fixxpert(expert_session)
      ExpertSessionsMailer.delay(queue: :mailer).passed_unconfirmed_session_email_customer(expert_session)
    end
  end
end