Removes deprecated 'return's from transaction blocks
This commit is contained in:
parent
6dc372076e
commit
c70a4afbbe
10 changed files with 27 additions and 34 deletions
|
@ -232,8 +232,8 @@ class Nonprofit < ApplicationRecord
|
||||||
|
|
||||||
Card.transaction do
|
Card.transaction do
|
||||||
active_cards.update_all inactive: true
|
active_cards.update_all inactive: true
|
||||||
return cards << card
|
|
||||||
end
|
end
|
||||||
|
cards << card
|
||||||
end
|
end
|
||||||
|
|
||||||
def active_card
|
def active_card
|
||||||
|
|
|
@ -49,13 +49,13 @@ module CreateCampaignGift
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Qx.transaction do
|
# are any gifts available?
|
||||||
# are any gifts available?
|
if campaign_gift_option.quantity.nil? || campaign_gift_option.quantity.zero? || campaign_gift_option.total_gifts < campaign_gift_option.quantity
|
||||||
if campaign_gift_option.quantity.nil? || campaign_gift_option.quantity.zero? || campaign_gift_option.total_gifts < campaign_gift_option.quantity
|
gift = CampaignGift.new params
|
||||||
gift = CampaignGift.new params
|
Qx.transaction do
|
||||||
gift.save!
|
gift.save!
|
||||||
return gift
|
|
||||||
end
|
end
|
||||||
|
return gift
|
||||||
end
|
end
|
||||||
AdminFailedGiftJob.perform_later(donation, campaign_gift_option)
|
AdminFailedGiftJob.perform_later(donation, campaign_gift_option)
|
||||||
raise ParamValidation::ValidationError.new("#{params[:campaign_gift_option_id]} has no more inventory", key: :campaign_gift_option_id)
|
raise ParamValidation::ValidationError.new("#{params[:campaign_gift_option_id]} has no more inventory", key: :campaign_gift_option_id)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
module ImportCivicrmPayments
|
module ImportCivicrmPayments
|
||||||
## MINIMALLY TESTED!!!
|
## MINIMALLY TESTED!!!
|
||||||
def self.import_from_csv(csv_body, nonprofit, field_of_supporter_id)
|
def self.import_from_csv(csv_body, nonprofit, field_of_supporter_id)
|
||||||
|
questionable_records = []
|
||||||
Qx.transaction do
|
Qx.transaction do
|
||||||
CSV::Converters[:blank_to_nil] = lambda do |field|
|
CSV::Converters[:blank_to_nil] = lambda do |field|
|
||||||
field && field.empty? ? nil : field
|
field && field.empty? ? nil : field
|
||||||
|
@ -21,7 +22,6 @@ module ImportCivicrmPayments
|
||||||
end
|
end
|
||||||
|
|
||||||
supporters_with_fields = Supporter.includes(:custom_field_joins).where('supporters.nonprofit_id = ? AND custom_field_joins.custom_field_master_id = ?', nonprofit.id, supporter_id_custom_field.id)
|
supporters_with_fields = Supporter.includes(:custom_field_joins).where('supporters.nonprofit_id = ? AND custom_field_joins.custom_field_master_id = ?', nonprofit.id, supporter_id_custom_field.id)
|
||||||
questionable_records = []
|
|
||||||
contrib_records.each do |r|
|
contrib_records.each do |r|
|
||||||
our_supporter = supporters_with_fields.where('custom_field_joins.value = ?', r[field_of_supporter_id].to_s).first
|
our_supporter = supporters_with_fields.where('custom_field_joins.value = ?', r[field_of_supporter_id].to_s).first
|
||||||
unless our_supporter
|
unless our_supporter
|
||||||
|
@ -62,8 +62,8 @@ module ImportCivicrmPayments
|
||||||
puts d
|
puts d
|
||||||
pay_imp.donations.push(Donation.find(d[:json]['donation']['id']))
|
pay_imp.donations.push(Donation.find(d[:json]['donation']['id']))
|
||||||
end
|
end
|
||||||
questionable_records
|
|
||||||
end
|
end
|
||||||
|
questionable_records
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.undo(import_id)
|
def self.undo(import_id)
|
||||||
|
|
|
@ -55,7 +55,7 @@ module InsertBankAccount
|
||||||
)
|
)
|
||||||
|
|
||||||
BankAccountCreateJob.perform_later(bank_account)
|
BankAccountCreateJob.perform_later(bank_account)
|
||||||
return bank_account
|
bank_account
|
||||||
rescue Stripe::StripeError => error
|
rescue Stripe::StripeError => error
|
||||||
params[:failure_message] = "Failed to connect the bank account: #{error.inspect}"
|
params[:failure_message] = "Failed to connect the bank account: #{error.inspect}"
|
||||||
raise ArgumentError, "Failed to connect the bank account: #{error.inspect}"
|
raise ArgumentError, "Failed to connect the bank account: #{error.inspect}"
|
||||||
|
|
|
@ -40,16 +40,14 @@ module InsertCustomFieldJoins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Qx.transaction do
|
cfm_id_to_value = field_data.map do |name, value|
|
||||||
# get the custom_field_master_id for each field_data name
|
cfm = CustomFieldMaster.where('nonprofit_id = ? and name = ?', np_id, name).first
|
||||||
cfm_id_to_value = field_data.map do |name, value|
|
Qx.transaction do
|
||||||
cfm = CustomFieldMaster.where('nonprofit_id = ? and name = ?', np_id, name).first
|
|
||||||
cfm ||= CustomFieldMaster.create!(nonprofit: np, name: name)
|
cfm ||= CustomFieldMaster.create!(nonprofit: np, name: name)
|
||||||
{ custom_field_master_id: cfm.id, value: value }
|
|
||||||
end
|
end
|
||||||
|
{ custom_field_master_id: cfm.id, value: value }
|
||||||
return in_bulk(np_id, supporter_ids, cfm_id_to_value)
|
|
||||||
end
|
end
|
||||||
|
in_bulk(np_id, supporter_ids, cfm_id_to_value)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Validation: *np_id is valid, corresponds to real nonprofit
|
# Validation: *np_id is valid, corresponds to real nonprofit
|
||||||
|
|
|
@ -17,9 +17,8 @@ module InsertDuplicate
|
||||||
raise ParamValidation::ValidationError.new("#{profile_id} is not a valid profile", key: :profile_id)
|
raise ParamValidation::ValidationError.new("#{profile_id} is not a valid profile", key: :profile_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dupe = campaign.dup
|
||||||
Qx.transaction do
|
Qx.transaction do
|
||||||
dupe = campaign.dup
|
|
||||||
|
|
||||||
dupe.slug = SlugCopyNamingAlgorithm.new(Campaign, dupe.nonprofit.id).create_copy_name(dupe.slug)
|
dupe.slug = SlugCopyNamingAlgorithm.new(Campaign, dupe.nonprofit.id).create_copy_name(dupe.slug)
|
||||||
dupe.name = NameCopyNamingAlgorithm.new(Campaign, dupe.nonprofit.id).create_copy_name(dupe.name)
|
dupe.name = NameCopyNamingAlgorithm.new(Campaign, dupe.nonprofit.id).create_copy_name(dupe.name)
|
||||||
if dupe.end_datetime && dupe.end_datetime.ago(7.days) < DateTime.now
|
if dupe.end_datetime && dupe.end_datetime.ago(7.days) < DateTime.now
|
||||||
|
@ -30,15 +29,14 @@ module InsertDuplicate
|
||||||
|
|
||||||
dupe.save!
|
dupe.save!
|
||||||
|
|
||||||
|
|
||||||
dupe.main_image.attach(campaign.main_image.blob) if campaign.main_image.attached?
|
dupe.main_image.attach(campaign.main_image.blob) if campaign.main_image.attached?
|
||||||
|
|
||||||
dupe.background_image.attach(campaign.background_image.blob) if campaign.background_image.attached?
|
dupe.background_image.attach(campaign.background_image.blob) if campaign.background_image.attached?
|
||||||
|
|
||||||
InsertDuplicate.campaign_gift_options(campaign_id, dupe.id)
|
InsertDuplicate.campaign_gift_options(campaign_id, dupe.id)
|
||||||
|
|
||||||
return dupe
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dupe
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.event(event_id, profile_id)
|
def self.event(event_id, profile_id)
|
||||||
|
@ -55,9 +53,8 @@ module InsertDuplicate
|
||||||
raise ParamValidation::ValidationError.new("#{profile_id} is not a valid profile", key: :profile_id)
|
raise ParamValidation::ValidationError.new("#{profile_id} is not a valid profile", key: :profile_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dupe = event.dup
|
||||||
Qx.transaction do
|
Qx.transaction do
|
||||||
dupe = event.dup
|
|
||||||
|
|
||||||
dupe.slug = SlugCopyNamingAlgorithm.new(Event, dupe.nonprofit.id).create_copy_name(dupe.slug)
|
dupe.slug = SlugCopyNamingAlgorithm.new(Event, dupe.nonprofit.id).create_copy_name(dupe.slug)
|
||||||
dupe.name = NameCopyNamingAlgorithm.new(Event, dupe.nonprofit.id).create_copy_name(dupe.name)
|
dupe.name = NameCopyNamingAlgorithm.new(Event, dupe.nonprofit.id).create_copy_name(dupe.name)
|
||||||
|
|
||||||
|
@ -77,16 +74,14 @@ module InsertDuplicate
|
||||||
|
|
||||||
dupe.save!
|
dupe.save!
|
||||||
|
|
||||||
|
|
||||||
dupe.main_image.attach(event.main_image.blob) if event.main_image.attached?
|
dupe.main_image.attach(event.main_image.blob) if event.main_image.attached?
|
||||||
|
|
||||||
dupe.background_image.attach( event.background_image.blob) if event.background_image.attached?
|
dupe.background_image.attach( event.background_image.blob) if event.background_image.attached?
|
||||||
|
|
||||||
InsertDuplicate.ticket_levels(event_id, dupe.id)
|
InsertDuplicate.ticket_levels(event_id, dupe.id)
|
||||||
InsertDuplicate.event_discounts(event_id, dupe.id)
|
InsertDuplicate.event_discounts(event_id, dupe.id)
|
||||||
|
|
||||||
return dupe
|
|
||||||
end
|
end
|
||||||
|
dupe
|
||||||
end
|
end
|
||||||
|
|
||||||
# selects all gift options associated with old campaign
|
# selects all gift options associated with old campaign
|
||||||
|
|
|
@ -37,6 +37,7 @@ module InsertPayout
|
||||||
totals = QueryPayments.get_payout_totals(payment_ids)
|
totals = QueryPayments.get_payout_totals(payment_ids)
|
||||||
nonprofit_currency = entities[:np_id].currency
|
nonprofit_currency = entities[:np_id].currency
|
||||||
now = Time.current
|
now = Time.current
|
||||||
|
payout = nil
|
||||||
begin
|
begin
|
||||||
stripe_transfer = StripeUtils.create_transfer(totals['net_amount'], data[:stripe_account_id], nonprofit_currency)
|
stripe_transfer = StripeUtils.create_transfer(totals['net_amount'], data[:stripe_account_id], nonprofit_currency)
|
||||||
Psql.transaction do
|
Psql.transaction do
|
||||||
|
@ -71,8 +72,8 @@ module InsertPayout
|
||||||
# Create PaymentPayout records linking all the payments to the payout
|
# Create PaymentPayout records linking all the payments to the payout
|
||||||
pps = Psql.execute(Qexpr.new.insert('payment_payouts', payment_ids.map { |id| { payment_id: id.to_i } }, common_data: { payout_id: payout['id'].to_i }))
|
pps = Psql.execute(Qexpr.new.insert('payment_payouts', payment_ids.map { |id| { payment_id: id.to_i } }, common_data: { payout_id: payout['id'].to_i }))
|
||||||
PayoutPendingJob.perform_later(Payout.find(payout['id'].to_i))
|
PayoutPendingJob.perform_later(Payout.find(payout['id'].to_i))
|
||||||
return payout
|
|
||||||
end
|
end
|
||||||
|
payout
|
||||||
rescue Stripe::StripeError => e
|
rescue Stripe::StripeError => e
|
||||||
payout = Psql.execute(
|
payout = Psql.execute(
|
||||||
Qexpr.new.insert(:payouts, [{
|
Qexpr.new.insert(:payouts, [{
|
||||||
|
@ -91,7 +92,7 @@ module InsertPayout
|
||||||
}])
|
}])
|
||||||
.returning('id', 'net_amount', 'nonprofit_id', 'created_at', 'updated_at', 'status', 'fee_total', 'gross_amount', 'email', 'count', 'stripe_transfer_id', 'user_ip', 'ach_fee', 'bank_name')
|
.returning('id', 'net_amount', 'nonprofit_id', 'created_at', 'updated_at', 'status', 'fee_total', 'gross_amount', 'email', 'count', 'stripe_transfer_id', 'user_ip', 'ach_fee', 'bank_name')
|
||||||
).first
|
).first
|
||||||
return payout
|
payout
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ module InsertSupporterNotes
|
||||||
# note: parameters to pass into the note
|
# note: parameters to pass into the note
|
||||||
def self.create(*note_supporter_users)
|
def self.create(*note_supporter_users)
|
||||||
inserted = nil
|
inserted = nil
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
inserted = note_supporter_users.map do |nsu|
|
inserted = note_supporter_users.map do |nsu|
|
||||||
nsu[:supporter].supporter_notes.create!(content: nsu[:content], user: nsu[:user])
|
nsu[:supporter].supporter_notes.create!(content: nsu[:content], user: nsu[:user])
|
||||||
end
|
end
|
||||||
|
|
|
@ -70,9 +70,9 @@ module UpdateDonation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
donation = existing_payment.donation
|
||||||
|
ret = donation.attributes
|
||||||
Qx.transaction do
|
Qx.transaction do
|
||||||
donation = existing_payment.donation
|
|
||||||
|
|
||||||
donation.designation = data[:designation] if data[:designation]
|
donation.designation = data[:designation] if data[:designation]
|
||||||
donation.comment = data[:comment] if data[:comment]
|
donation.comment = data[:comment] if data[:comment]
|
||||||
donation.dedication = data[:dedication] if data[:dedication]
|
donation.dedication = data[:dedication] if data[:dedication]
|
||||||
|
@ -133,7 +133,7 @@ module UpdateDonation
|
||||||
ret = donation.attributes
|
ret = donation.attributes
|
||||||
ret[:payment] = existing_payment.attributes
|
ret[:payment] = existing_payment.attributes
|
||||||
ret[:offsite_payment] = offsite_payment.attributes if is_offsite
|
ret[:offsite_payment] = offsite_payment.attributes if is_offsite
|
||||||
return ret
|
|
||||||
end
|
end
|
||||||
|
ret
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,8 +34,7 @@ module UpdatePayouts
|
||||||
payout.status = status
|
payout.status = status
|
||||||
payout.failure_message = failure_message
|
payout.failure_message = failure_message
|
||||||
payout.save!
|
payout.save!
|
||||||
|
|
||||||
payout
|
|
||||||
end
|
end
|
||||||
|
payout
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue