Move some common elements of TransactionAssignments to a single module

This commit is contained in:
Eric Schultz 2021-02-10 17:48:18 -06:00 committed by Eric Schultz
parent d0197eb62e
commit dad2873314
4 changed files with 28 additions and 32 deletions

View file

@ -3,23 +3,14 @@
# 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 CampaignGiftPurchase < ApplicationRecord
include Model::Houidable
include Model::Jbuilder
include Model::Eventable
include Model::TrxAssignable
setup_houid :cgpur
belongs_to :campaign
has_many :campaign_gifts, class_name: 'ModernCampaignGift'
add_builder_expansion :nonprofit, :supporter, :campaign
add_builder_expansion :trx,
json_attrib: :transaction
has_one :transaction_assignment, as: :assignable
has_one :trx, through: :transaction_assignment
has_one :supporter, through: :trx
has_one :nonprofit, through: :supporter
add_builder_expansion :campaign
# TODO replace with Discard gem

View file

@ -0,0 +1,23 @@
# 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
module Model::TrxAssignable
extend ActiveSupport::Concern
included do
include Model::Houidable
include Model::Jbuilder
include Model::Eventable
add_builder_expansion :nonprofit, :supporter
add_builder_expansion :trx,
json_attrib: :transaction
has_one :transaction_assignment, as: :assignable
has_one :trx, through: :transaction_assignment
has_one :supporter, through: :trx
has_one :nonprofit, through: :supporter
end
end

View file

@ -3,20 +3,10 @@
# 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 ModernDonation < ApplicationRecord
include Model::Houidable
include Model::Jbuilder
include Model::Eventable
include Model::TrxAssignable
setup_houid :don
# TODO must associate with events and campaigns somehow
add_builder_expansion :nonprofit, :supporter
add_builder_expansion :trx,
json_attrib: :transaction
has_one :transaction_assignment, as: :assignable
has_one :trx, through: :transaction_assignment
has_one :supporter, through: :trx
has_one :nonprofit, through: :supporter
belongs_to :legacy_donation, class_name: 'Donation', foreign_key: :donation_id, inverse_of: :modern_donation
delegate :designation, :dedication, to: :legacy_donation

View file

@ -3,14 +3,10 @@
# 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 TicketPurchase < ApplicationRecord
include Model::Houidable
include Model::Jbuilder
include Model::Eventable
include Model::TrxAssignable
setup_houid :tktpur
add_builder_expansion :event, :nonprofit, :supporter
add_builder_expansion :trx,
json_attrib: :transaction
add_builder_expansion :event
add_builder_expansion :event_discount,
to_id: -> (model) { model.event_discount&.id },
@ -20,10 +16,6 @@ class TicketPurchase < ApplicationRecord
belongs_to :event_discount
belongs_to :event
has_one :transaction_assignment, as: :assignable
has_one :trx, through: :transaction_assignment
has_one :supporter, through: :trx
has_one :nonprofit, through: :supporter
has_many :ticket_to_legacy_tickets