Merge pull request #1642 from siddhantbajaj/user-present

Improving check-in process
This commit is contained in:
Ana María Martínez Gómez 2017-09-20 22:37:07 +02:00 committed by GitHub
commit 7e9d1dbf84
5 changed files with 49 additions and 2 deletions

View file

@ -1,3 +1,13 @@
class TicketScanning < ActiveRecord::Base
belongs_to :physical_ticket
before_create :mark_user_present
private
def mark_user_present
if physical_ticket.ticket.registration_ticket?
physical_ticket.user.mark_attendance_for_conference(physical_ticket.conference)
end
end
end

View file

@ -47,7 +47,11 @@ class User < ActiveRecord::Base
has_many :event_users, dependent: :destroy
has_many :events, -> { uniq }, through: :event_users
has_many :presented_events, -> { joins(:event_users).where(event_users: {event_role: 'speaker'}).uniq }, through: :event_users, source: :event
has_many :registrations, dependent: :destroy
has_many :registrations, dependent: :destroy do
def for_conference conference
where(conference: conference).first
end
end
has_many :events_registrations, through: :registrations
has_many :ticket_purchases, dependent: :destroy
has_many :payments, dependent: :destroy
@ -93,6 +97,12 @@ class User < ActiveRecord::Base
event_registration.attended
end
def mark_attendance_for_conference conference
registration = registrations.for_conference(conference)
registration.attended = true
registration.save
end
def name
self[:name].blank? ? username : self[:name]
end