added more conditions

This commit is contained in:
rajavi-mishra 2021-03-03 13:58:36 -08:00
parent 48a689d452
commit 8c230352f9

View file

@ -29,24 +29,42 @@ class TicketPurchasesController < ApplicationController
# TODO: User already paid for a registration ticket and ticket purchase contains one # TODO: User already paid for a registration ticket and ticket purchase contains one
# BUG: When the ticket is free, user will see the notice after they click `Continue` # BUG: When the ticket is free, user will see the notice after they click `Continue`
# Two types of ticket? # this works? maybe
# TODO: Need to check # TODO: Need to check
if current_user.ticket_purchases.by_conference(@conference).paid.any? if current_user.ticket_purchases.by_conference(@conference).paid.any?
redirect_to conference_physical_tickets_path, for ticket_purchase in current_user.ticket_purchases.by_conference(@conference)
notice: 'You already have tickets for the conference.' if ticket_purchase.paid?
return for physical_ticket in ticket_purchase.physical_tickets
if physical_ticket.ticket.registration_ticket?
redirect_to conference_physical_tickets_path,
notice: 'You already have tickets for the conference.'
return
end
end
end
end end
# TODO: User wants to purchase a non-registration ticket but does not have a registration ticket but conference requires one # TODO: User wants to purchase a non-registration ticket but does not have a registration ticket but conference requires one
# BUG: When the user only purchases a non-registration ticket, # BUG: When the user only purchases a non-registration ticket,
if @conference.registration_ticket_required? if @conference.registration_ticket_required?
redirect_to conference_tickets_path(@conference.short_title), seen_registration = false
error: 'Please get at least one ticket to continue.' for ticket_purchase in current_user.ticket_purchases.by_conference(@conference)
return for physical_ticket in ticket_purchase.physical_tickets
if physical_ticket.ticket.registration_ticket
seen = true
break
end
end
end
if !seen
redirect_to conference_tickets_path(@conference.short_title),
error: 'Please get at least one registration ticket to continue.'
return
end
end end
# TODO: Need to check if the current user didn't a registration ticket and is purchasing one # TODO: Need to check if the current user didn't have a registration ticket and is purchasing one
redirect_to new_conference_conference_registration_path(@conference.short_title) redirect_to new_conference_conference_registration_path(@conference.short_title)
# # otherwise # # otherwise
# redirect_to conference_physical_tickets_path # redirect_to conference_physical_tickets_path