develop #3
@@ -96,6 +96,12 @@ class Event < ApplicationRecord
|
|||||||
Time.current >= end_time
|
Time.current >= end_time
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Check if booking is allowed during the event
|
||||||
|
# This is a simple attribute reader that defaults to false if nil
|
||||||
|
def allow_booking_during_event?
|
||||||
|
!!allow_booking_during_event
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Determine if we should perform server-side geocoding
|
# Determine if we should perform server-side geocoding
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class TicketType < ApplicationRecord
|
class TicketType < ApplicationRecord
|
||||||
# Associations
|
# Associations
|
||||||
belongs_to :event
|
belongs_to :event
|
||||||
has_many :tickets, dependent: :destroy
|
has_many :tickets, dependent: :destroy # Cannot delete ticket types if already tickets sold
|
||||||
|
|
||||||
# Validations
|
# Validations
|
||||||
validates :name, presence: true, length: { minimum: 3, maximum: 50 }
|
validates :name, presence: true, length: { minimum: 3, maximum: 50 }
|
||||||
@@ -80,6 +80,10 @@ class TicketType < ApplicationRecord
|
|||||||
|
|
||||||
def sale_times_within_event_period
|
def sale_times_within_event_period
|
||||||
return unless event&.start_time && sale_end_at
|
return unless event&.start_time && sale_end_at
|
||||||
|
|
||||||
|
# Only enforce this restriction if booking during event is not allowed
|
||||||
|
unless event.allow_booking_during_event?
|
||||||
errors.add(:sale_end_at, "cannot be after the event starts") if sale_end_at > event.start_time
|
errors.add(:sale_end_at, "cannot be after the event starts") if sale_end_at > event.start_time
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user