modify controllers and models to just save paid ticket purchases
This commit is contained in:
parent
900a1b32a8
commit
81ef41be8b
4 changed files with 25 additions and 17 deletions
|
|
@ -7,10 +7,6 @@ class TicketPurchase < ActiveRecord::Base
|
|||
|
||||
validates_numericality_of :quantity, greater_than: 0
|
||||
|
||||
validates_uniqueness_of :user_id,
|
||||
scope: :ticket_id,
|
||||
message: 'already bought this ticket!'
|
||||
|
||||
delegate :title, to: :ticket
|
||||
delegate :description, to: :ticket
|
||||
delegate :price, to: :ticket
|
||||
|
|
@ -23,7 +19,7 @@ class TicketPurchase < ActiveRecord::Base
|
|||
conference.tickets.each do |ticket|
|
||||
quantity = purchases[ticket.id.to_s].to_i
|
||||
# if the user bought the ticket, just update the quantity
|
||||
if ticket.bought?(user)
|
||||
if ticket.bought?(user) && ticket.unpaid?(user)
|
||||
purchase = update_quantity(conference, quantity, ticket, user)
|
||||
else
|
||||
purchase = purchase_ticket(conference, quantity, ticket, user)
|
||||
|
|
@ -48,7 +44,8 @@ class TicketPurchase < ActiveRecord::Base
|
|||
def self.update_quantity(conference, quantity, ticket, user)
|
||||
purchase = TicketPurchase.where(ticket_id: ticket.id,
|
||||
conference_id: conference.id,
|
||||
user_id: user.id).first
|
||||
user_id: user.id,
|
||||
paid: 'f').first
|
||||
|
||||
purchase.quantity = quantity if quantity > 0
|
||||
purchase
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue