2021-02-02 21:04:53 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
|
|
|
class TicketToLegacyTicket < ApplicationRecord
|
|
|
|
include Model::Houidable
|
|
|
|
include Model::Jbuilder
|
2021-02-02 23:48:05 +00:00
|
|
|
include Model::Eventable
|
|
|
|
|
2021-02-02 21:04:53 +00:00
|
|
|
belongs_to :ticket_purchase
|
|
|
|
belongs_to :ticket
|
|
|
|
|
|
|
|
has_one :ticket_level, through: :ticket
|
|
|
|
has_one :event, through: :ticket_purchase
|
|
|
|
has_one :event_discount, through: :ticket_purchase
|
|
|
|
has_one :supporter, through: :ticket_purchase
|
|
|
|
has_one :nonprofit, through: :event
|
|
|
|
|
|
|
|
delegate :original_discount, to: :ticket_purchase
|
|
|
|
delegate :checked_in, :deleted, :note, to: :ticket
|
|
|
|
|
|
|
|
setup_houid :tkt
|
|
|
|
|
2021-04-07 21:43:58 +00:00
|
|
|
add_builder_expansion :ticket_purchase, :ticket_level, :supporter, :event, :nonprofit, :event_discount
|
2021-02-02 21:04:53 +00:00
|
|
|
|
|
|
|
def to_builder(*expand)
|
|
|
|
init_builder(*expand) do |json|
|
2021-02-12 21:29:55 +00:00
|
|
|
json.(self, :checked_in, :deleted, :note)
|
2021-02-02 21:04:53 +00:00
|
|
|
json.object "ticket"
|
|
|
|
|
|
|
|
json.amount do
|
2021-02-26 20:23:29 +00:00
|
|
|
json.cents amount
|
2021-02-02 21:04:53 +00:00
|
|
|
json.currency nonprofit.currency
|
|
|
|
end
|
|
|
|
|
|
|
|
if original_discount
|
|
|
|
json.original_discount do
|
|
|
|
json.percent original_discount
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-02 23:48:05 +00:00
|
|
|
def publish_created
|
|
|
|
Houdini.event_publisher.announce(:ticket_created, to_event('ticket.created',
|
|
|
|
:ticket_purchase,
|
|
|
|
:ticket_level,
|
|
|
|
:supporter,
|
|
|
|
:event,
|
|
|
|
:nonprofit,
|
|
|
|
:event_discount).attributes!)
|
|
|
|
end
|
|
|
|
|
2021-02-03 22:27:31 +00:00
|
|
|
def publish_updated
|
|
|
|
Houdini.event_publisher.announce(:ticket_updated, to_event('ticket.updated',
|
|
|
|
:ticket_purchase,
|
|
|
|
:ticket_level,
|
|
|
|
:supporter,
|
|
|
|
:event,
|
|
|
|
:nonprofit,
|
|
|
|
:event_discount).attributes!)
|
|
|
|
end
|
|
|
|
|
2021-02-03 22:44:24 +00:00
|
|
|
def publish_deleted
|
|
|
|
Houdini.event_publisher.announce(:ticket_deleted, to_event('ticket.deleted',
|
|
|
|
:ticket_purchase,
|
|
|
|
:ticket_level,
|
|
|
|
:supporter,
|
|
|
|
:event,
|
|
|
|
:nonprofit,
|
|
|
|
:event_discount).attributes!)
|
|
|
|
end
|
|
|
|
|
2021-02-02 21:04:53 +00:00
|
|
|
end
|