From ee43996a77c103f193e73b7f8d258c2420f18a39 Mon Sep 17 00:00:00 2001 From: kbe Date: Mon, 15 Sep 2025 19:07:19 +0200 Subject: [PATCH] feat(book after start): prepare to rework event to allow ticket sell after start --- app/models/event.rb | 6 ++++++ app/models/ticket_type.rb | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/models/event.rb b/app/models/event.rb index d01941c..35bb3a2 100755 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -96,6 +96,12 @@ class Event < ApplicationRecord Time.current >= end_time 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 # Determine if we should perform server-side geocoding diff --git a/app/models/ticket_type.rb b/app/models/ticket_type.rb index 2bca6cd..f06cfd5 100755 --- a/app/models/ticket_type.rb +++ b/app/models/ticket_type.rb @@ -1,7 +1,7 @@ class TicketType < ApplicationRecord # Associations belongs_to :event - has_many :tickets, dependent: :destroy + has_many :tickets, dependent: :destroy # Cannot delete ticket types if already tickets sold # Validations validates :name, presence: true, length: { minimum: 3, maximum: 50 } @@ -80,6 +80,10 @@ class TicketType < ApplicationRecord def sale_times_within_event_period return unless event&.start_time && sale_end_at - errors.add(:sale_end_at, "cannot be after the event starts") if sale_end_at > event.start_time + + # 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 + end end end