class TutoringSessionView

Schema Information

Table name: tutoring_session_views

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

Public Class Methods

billing_reminder() click to toggle source

send email notifications for completed session

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

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

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

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

    tutoring_sessions.each do |tutoring_session|
      begin
        puts "paying tutor"
        invoice = Invoice.find_by(invoiceable_id: tutoring_session.id)
        invoice.pay_tutor
      rescue
        next
      end
    end
  end
end
reminder_to_attend_session() click to toggle source

Send reminder to tutor to attend the session.

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

Send mail to tutor to confirm the session.(i.e. to accept request of tutoring session)

# File app/models/tutoring_session_view.rb, line 61
def self.reminder_to_confirm_session
  tutoring_sessions = TutoringSession.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 = tutoring_sessions.id and ns.resource_type = "TutoringSession" and ns.notification_type = "confirmation_reminder")', Time.now.in_time_zone, Time.now.in_time_zone + 3.hours)
  tutoring_sessions.find_each do |tutoring_session|
    if tutoring_session.build_confirmation_reminder(user_id: tutoring_session.user_id, sent_at: Time.now.in_time_zone).save
      TutoringSessionsMailer.delay(queue: :mailer).confirmation_reminder_email_tutor(tutoring_session)
    end
  end
end
send_notification_for_unconfirmed_sessions() click to toggle source

Send mail to users for unconfirmed session.

# File app/models/tutoring_session_view.rb, line 82
def self.send_notification_for_unconfirmed_sessions
  TutoringSession.unnotified_expired_pending_sessions.find_each do |tutoring_session|
    tutoring_session.notification_sent_at = Time.now.in_time_zone
    if tutoring_session.save(validate: false)
      TutoringSessionsMailer.delay(queue: :mailer).passed_unconfirmed_session_email_tutor(tutoring_session)
      TutoringSessionsMailer.delay(queue: :mailer).passed_unconfirmed_session_email_student(tutoring_session)
    end
  end
end