Class: Mobile::TicketsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/mobile/tickets_controller.rb

Constant Summary collapse

OrganizationNotFound =
Class.new(Exception)
TicketNotFound =
Class.new(Exception)
TicketAlreadyValidated =
Class.new(Exception)
TicketNotValidated =
Class.new(Exception)

Instance Method Summary collapse

Instance Method Details

#orderObject



68
69
70
71
72
73
74
75
76
# File 'app/controllers/mobile/tickets_controller.rb', line 68

def order
  organization = current_user.organizations.find_by_id(params[:organization_id])
  raise OrganizationNotFound, "Could not load order" if !organization
  ticket = organization.tickets.find_by_uuid(params[:id])
  raise TicketNotFound, "Could not load order" if !ticket
  order = ticket.sold_item.try(:order)

  render :json => order, :serializer => OrderSerializer
end

#showObject



59
60
61
62
63
64
65
66
# File 'app/controllers/mobile/tickets_controller.rb', line 59

def show
  organization = current_user.organizations.find_by_id(params[:organization_id])
  raise OrganizationNotFound, "Could not load ticket" if !organization
  ticket = organization.tickets.find_by_uuid(params[:id])
  raise TicketNotFound, "Could not load ticket" if !ticket

  render :json => ticket
end

#unvalidateObject



102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/controllers/mobile/tickets_controller.rb', line 102

def unvalidate
  organization = current_user.organizations.find_by_id(params[:organization_id])
  raise OrganizationNotFound, "Could not update ticket" if !organization
  ticket = organization.tickets.where(:show_id => params[:show_id], :uuid => params[:id]).first
  raise TicketNotFound, "Could not update ticket" if !ticket

  if !ticket.unvalidate_ticket!
    raise TicketNotValidated
  end

  render :json => ticket.sold_item.try(:order), :serializer => OrderValidationSerializer
end

#validateObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/controllers/mobile/tickets_controller.rb', line 78

def validate
  organization = current_user.organizations.find_by_id(params[:organization_id])
  raise OrganizationNotFound, "Could not update ticket" if !organization

  ticket = organization.tickets.where(:show_id => params[:show_id], :uuid => params[:id]).first
  if !ticket
    # Try a member walkup
    walkup = MemberWalkup.new(:show_id => params[:show_id], :member_uuid => params[:id])

    if walkup.valid?
      walkup.save
      ticket = walkup.ticket
    end

    raise TicketNotFound, "Could not update ticket" unless ticket
  end

  if !ticket.validate_ticket!(current_user)
    raise TicketAlreadyValidated
  end

  render :json => ticket.sold_item.try(:order), :serializer => OrderValidationSerializer
end