Removes deprecated 'return's from transaction blocks

This commit is contained in:
Clarissa Borges 2021-03-06 18:54:01 -03:00 committed by Eric Schultz
parent 6dc372076e
commit c70a4afbbe
10 changed files with 27 additions and 34 deletions

View file

@ -232,8 +232,8 @@ class Nonprofit < ApplicationRecord
Card.transaction do
active_cards.update_all inactive: true
return cards << card
end
cards << card
end
def active_card

View file

@ -49,13 +49,13 @@ module CreateCampaignGift
end
end
Qx.transaction do
# are any gifts available?
if campaign_gift_option.quantity.nil? || campaign_gift_option.quantity.zero? || campaign_gift_option.total_gifts < campaign_gift_option.quantity
gift = CampaignGift.new params
Qx.transaction do
gift.save!
return gift
end
return gift
end
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)

View file

@ -5,6 +5,7 @@
module ImportCivicrmPayments
## MINIMALLY TESTED!!!
def self.import_from_csv(csv_body, nonprofit, field_of_supporter_id)
questionable_records = []
Qx.transaction do
CSV::Converters[:blank_to_nil] = lambda do |field|
field && field.empty? ? nil : field
@ -21,7 +22,6 @@ module ImportCivicrmPayments
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)
questionable_records = []
contrib_records.each do |r|
our_supporter = supporters_with_fields.where('custom_field_joins.value = ?', r[field_of_supporter_id].to_s).first
unless our_supporter
@ -62,8 +62,8 @@ module ImportCivicrmPayments
puts d
pay_imp.donations.push(Donation.find(d[:json]['donation']['id']))
end
questionable_records
end
questionable_records
end
def self.undo(import_id)

View file

@ -55,7 +55,7 @@ module InsertBankAccount
)
BankAccountCreateJob.perform_later(bank_account)
return bank_account
bank_account
rescue Stripe::StripeError => error
params[:failure_message] = "Failed to connect the bank account: #{error.inspect}"
raise ArgumentError, "Failed to connect the bank account: #{error.inspect}"

View file

@ -40,16 +40,14 @@ module InsertCustomFieldJoins
end
end
Qx.transaction do
# get the custom_field_master_id for each field_data name
cfm_id_to_value = field_data.map do |name, value|
cfm = CustomFieldMaster.where('nonprofit_id = ? and name = ?', np_id, name).first
Qx.transaction do
cfm ||= CustomFieldMaster.create!(nonprofit: np, name: name)
end
{ custom_field_master_id: cfm.id, value: value }
end
return in_bulk(np_id, supporter_ids, cfm_id_to_value)
end
in_bulk(np_id, supporter_ids, cfm_id_to_value)
end
# Validation: *np_id is valid, corresponds to real nonprofit

View file

@ -17,9 +17,8 @@ module InsertDuplicate
raise ParamValidation::ValidationError.new("#{profile_id} is not a valid profile", key: :profile_id)
end
Qx.transaction do
dupe = campaign.dup
Qx.transaction do
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)
if dupe.end_datetime && dupe.end_datetime.ago(7.days) < DateTime.now
@ -30,15 +29,14 @@ module InsertDuplicate
dupe.save!
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?
InsertDuplicate.campaign_gift_options(campaign_id, dupe.id)
return dupe
end
dupe
end
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)
end
Qx.transaction do
dupe = event.dup
Qx.transaction do
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)
@ -77,16 +74,14 @@ module InsertDuplicate
dupe.save!
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?
InsertDuplicate.ticket_levels(event_id, dupe.id)
InsertDuplicate.event_discounts(event_id, dupe.id)
return dupe
end
dupe
end
# selects all gift options associated with old campaign

View file

@ -37,6 +37,7 @@ module InsertPayout
totals = QueryPayments.get_payout_totals(payment_ids)
nonprofit_currency = entities[:np_id].currency
now = Time.current
payout = nil
begin
stripe_transfer = StripeUtils.create_transfer(totals['net_amount'], data[:stripe_account_id], nonprofit_currency)
Psql.transaction do
@ -71,8 +72,8 @@ module InsertPayout
# 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 }))
PayoutPendingJob.perform_later(Payout.find(payout['id'].to_i))
return payout
end
payout
rescue Stripe::StripeError => e
payout = Psql.execute(
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')
).first
return payout
payout
end
end
end

View file

@ -70,9 +70,9 @@ module UpdateDonation
end
end
Qx.transaction do
donation = existing_payment.donation
ret = donation.attributes
Qx.transaction do
donation.designation = data[:designation] if data[:designation]
donation.comment = data[:comment] if data[:comment]
donation.dedication = data[:dedication] if data[:dedication]
@ -133,7 +133,7 @@ module UpdateDonation
ret = donation.attributes
ret[:payment] = existing_payment.attributes
ret[:offsite_payment] = offsite_payment.attributes if is_offsite
return ret
end
end
ret
end
end

View file

@ -34,8 +34,7 @@ module UpdatePayouts
payout.status = status
payout.failure_message = failure_message
payout.save!
end
payout
end
end
end