Class: SchedulerBooking
Overview
== Schema Information
Table name: scheduler_bookings
Database name: primary
id :bigint not null, primary key
answers :jsonb
ends_at :datetime not null
guest_attendees :jsonb
guest_email :string not null
guest_name :string not null
guest_phone :string
location_type :string
notes :text
rescheduled_at :datetime
rescheduled_count :integer default(0), not null
starts_at :datetime not null
status :string default("confirmed"), not null
timezone :string default("America/Chicago"), not null
uuid :uuid not null
zoom_join_url :string
created_at :datetime not null
updated_at :datetime not null
employee_id :bigint not null
google_event_id :string
party_id :integer
scheduler_booking_page_id :bigint not null
zoom_meeting_id :string
Indexes
index_scheduler_bookings_on_employee_id_and_starts_at (employee_id,starts_at)
index_scheduler_bookings_on_party_id (party_id)
index_scheduler_bookings_on_scheduler_booking_page_id (scheduler_booking_page_id)
index_scheduler_bookings_on_starts_at (starts_at)
index_scheduler_bookings_on_status (status)
index_scheduler_bookings_on_uuid (uuid) UNIQUE
Foreign Keys
fk_rails_... (employee_id => parties.id) ON DELETE => cascade
fk_rails_... (scheduler_booking_page_id => scheduler_booking_pages.id) ON DELETE => cascade
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
#publish_event
Instance Attribute Details
#ends_at ⇒ Object
54
|
# File 'app/models/scheduler_booking.rb', line 54
validates :guest_name, :guest_email, :starts_at, :ends_at, :timezone, presence: true
|
#guest_email ⇒ Object
54
|
# File 'app/models/scheduler_booking.rb', line 54
validates :guest_name, :guest_email, :starts_at, :ends_at, :timezone, presence: true
|
#guest_name ⇒ Object
54
|
# File 'app/models/scheduler_booking.rb', line 54
validates :guest_name, :guest_email, :starts_at, :ends_at, :timezone, presence: true
|
#location_type ⇒ Object
57
|
# File 'app/models/scheduler_booking.rb', line 57
validates :location_type, inclusion: { in: %w[phone zoom] }, allow_nil: true
|
#starts_at ⇒ Object
54
|
# File 'app/models/scheduler_booking.rb', line 54
validates :guest_name, :guest_email, :starts_at, :ends_at, :timezone, presence: true
|
#timezone ⇒ Object
54
|
# File 'app/models/scheduler_booking.rb', line 54
validates :guest_name, :guest_email, :starts_at, :ends_at, :timezone, presence: true
|
#uuid ⇒ Object
56
|
# File 'app/models/scheduler_booking.rb', line 56
validates :uuid, uniqueness: true
|
Class Method Details
.cancelled ⇒ ActiveRecord::Relation<SchedulerBooking>
A relation of SchedulerBookings that are cancelled. Active Record Scope
61
|
# File 'app/models/scheduler_booking.rb', line 61
scope :cancelled, -> { where(status: 'cancelled') }
|
.confirmed ⇒ ActiveRecord::Relation<SchedulerBooking>
A relation of SchedulerBookings that are confirmed. Active Record Scope
60
|
# File 'app/models/scheduler_booking.rb', line 60
scope :confirmed, -> { where(status: 'confirmed') }
|
.for_employee_on_date ⇒ ActiveRecord::Relation<SchedulerBooking>
A relation of SchedulerBookings that are for employee on date. Active Record Scope
64
65
66
67
68
|
# File 'app/models/scheduler_booking.rb', line 64
scope :for_employee_on_date, ->(employee, date) {
confirmed
.where(employee: employee)
.where(starts_at: date.in_time_zone('America/Chicago').beginning_of_day..date.in_time_zone('America/Chicago').end_of_day)
}
|
A relation of SchedulerBookings that are past. Active Record Scope
63
|
# File 'app/models/scheduler_booking.rb', line 63
scope :past, -> { confirmed.where('starts_at <= ?', Time.current) }
|
.upcoming ⇒ ActiveRecord::Relation<SchedulerBooking>
A relation of SchedulerBookings that are upcoming. Active Record Scope
62
|
# File 'app/models/scheduler_booking.rb', line 62
scope :upcoming, -> { confirmed.where('starts_at > ?', Time.current) }
|
Instance Method Details
#activities ⇒ ActiveRecord::Relation<Activity>
50
|
# File 'app/models/scheduler_booking.rb', line 50
has_many :activities, as: :resource, dependent: :nullify
|
#customer_sales_rep_invite_email ⇒ Object
Email to add as a Google Calendar attendee when the booking page opts in and we resolve
an existing customer with a primary sales rep. Availability is not checked; the rep may accept or decline.
120
121
122
123
124
125
126
127
128
129
130
|
# File 'app/models/scheduler_booking.rb', line 120
def customer_sales_rep_invite_email
return unless scheduler_booking_page.invite_customer_sales_rep?
customer = SchedulerBookingLeadProcessor.customer_for_sales_rep_invite(self)
rep = customer&.primary_sales_rep
return unless rep&.email.present?
return if rep.id == employee_id
rep.email.to_s.strip.downcase
end
|
#duration_minutes ⇒ Object
86
87
88
|
# File 'app/models/scheduler_booking.rb', line 86
def duration_minutes
((ends_at - starts_at) / 60).to_i
end
|
#effective_location_type ⇒ Object
98
99
100
|
# File 'app/models/scheduler_booking.rb', line 98
def effective_location_type
location_type || scheduler_booking_page.location_type
end
|
47
|
# File 'app/models/scheduler_booking.rb', line 47
belongs_to :employee
|
#ends_at_in_guest_tz ⇒ Object
94
95
96
|
# File 'app/models/scheduler_booking.rb', line 94
def ends_at_in_guest_tz
ends_at.in_time_zone(timezone)
end
|
#link_party_ids ⇒ Object
114
115
116
|
# File 'app/models/scheduler_booking.rb', line 114
def link_party_ids
[party_id].compact
end
|
48
|
# File 'app/models/scheduler_booking.rb', line 48
belongs_to :party, optional: true
|
#reschedule!(new_starts_at, new_ends_at, new_timezone) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
|
# File 'app/models/scheduler_booking.rb', line 102
def reschedule!(new_starts_at, new_ends_at, new_timezone)
raise "Cannot reschedule a #{status} booking" unless confirmed?
update!(
starts_at: new_starts_at,
ends_at: new_ends_at,
timezone: new_timezone,
rescheduled_at: Time.current,
rescheduled_count: rescheduled_count + 1
)
end
|
46
|
# File 'app/models/scheduler_booking.rb', line 46
belongs_to :scheduler_booking_page
|
#starts_at_in_guest_tz ⇒ Object
90
91
92
|
# File 'app/models/scheduler_booking.rb', line 90
def starts_at_in_guest_tz
starts_at.in_time_zone(timezone)
end
|