2021-02-08 20:55:31 +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 ModernDonation < ApplicationRecord
|
2021-02-10 23:48:18 +00:00
|
|
|
include Model::TrxAssignable
|
2021-02-08 20:55:31 +00:00
|
|
|
setup_houid :don
|
|
|
|
|
|
|
|
# TODO must associate with events and campaigns somehow
|
2021-05-10 19:18:42 +00:00
|
|
|
belongs_to :legacy_donation, class_name: 'Donation', foreign_key: :donation_id, inverse_of: :modern_donations
|
2021-02-08 20:55:31 +00:00
|
|
|
|
|
|
|
delegate :designation, :dedication, to: :legacy_donation
|
|
|
|
|
2021-04-07 21:43:58 +00:00
|
|
|
def to_id
|
|
|
|
::Jbuilder.new do |json|
|
|
|
|
json.id id
|
|
|
|
json.object 'donation'
|
|
|
|
json.type 'trx_assignment'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-08 20:55:31 +00:00
|
|
|
def to_builder(*expand)
|
|
|
|
init_builder(*expand) do |json|
|
2021-02-12 21:29:55 +00:00
|
|
|
json.(self, :designation)
|
2021-02-08 20:55:31 +00:00
|
|
|
json.object 'donation'
|
2021-04-07 21:43:58 +00:00
|
|
|
json.type 'trx_assignment'
|
2021-02-08 20:55:31 +00:00
|
|
|
|
|
|
|
json.dedication do
|
|
|
|
json.type dedication['type']
|
|
|
|
json.name dedication['name']
|
|
|
|
contact = dedication['contact']
|
|
|
|
json.contact do
|
|
|
|
json.email contact['email'] if contact['email']
|
|
|
|
json.address contact['address'] if contact['address']
|
|
|
|
json.phone contact['phone'] if contact['phone']
|
|
|
|
end if contact
|
|
|
|
end if dedication
|
|
|
|
# TODO the line above is a hacky solution
|
|
|
|
|
|
|
|
json.amount do
|
2021-02-26 20:23:29 +00:00
|
|
|
json.cents amount
|
2021-02-08 20:55:31 +00:00
|
|
|
json.currency nonprofit.currency
|
|
|
|
end
|
2021-04-07 21:43:58 +00:00
|
|
|
|
|
|
|
json.add_builder_expansion :nonprofit, :supporter
|
|
|
|
json.add_builder_expansion :trx, json_attribute: :transaction
|
2021-02-08 20:55:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def publish_created
|
|
|
|
Houdini.event_publisher.announce(:donation_created, to_event('donation.created', :nonprofit, :supporter, :trx).attributes!)
|
2021-04-07 21:43:58 +00:00
|
|
|
Houdini.event_publisher.announce(:trx_assignment_created, to_event('trx_assignment.created', :nonprofit, :supporter, :trx).attributes!)
|
2021-02-08 20:55:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def publish_updated
|
|
|
|
Houdini.event_publisher.announce(:donation_updated, to_event('donation.updated', :nonprofit, :supporter, :trx).attributes!)
|
2021-04-07 21:43:58 +00:00
|
|
|
Houdini.event_publisher.announce(:trx_assignment_updated, to_event('trx_assignment.updated', :nonprofit, :supporter, :trx).attributes!)
|
2021-02-08 20:55:31 +00:00
|
|
|
end
|
|
|
|
end
|