-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add check for parameters on filter charges + fix db
- Loading branch information
1 parent
7b7a6da
commit a451edb
Showing
5 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
db/migrate/20241220084758_fix_charge_properties_with_double_values.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
class FixChargePropertiesWithDoubleValues < ActiveRecord::Migration[7.1] | ||
def up | ||
pairs = [['amount', 'graduated_ranges'], ['amount', 'graduated_percentage_ranges'], ['amount', 'volume_ranges']] | ||
pairs.each do |pair| | ||
ChargeFilter.includes(:charge).where("properties ?& array[:keys]", keys: pair).find_each do |cf| | ||
fix_charge_filter_properties(cf) | ||
end | ||
Charge.where("properties ?& array[:keys]", keys: pair).find_each do |charge| | ||
fix_charge_properties(charge) | ||
end | ||
end | ||
end | ||
|
||
def down | ||
end | ||
|
||
private | ||
|
||
def fix_charge_filter_properties(charge_filter) | ||
result = Charges::FilterChargeModelPropertiesService.call( | ||
charge: charge_filter.charge, properties: charge_filter.properties | ||
).raise_if_error! | ||
charge_filter.properties = result.properties | ||
charge.save! | ||
end | ||
|
||
def fix_charge_properties(charge) | ||
result = Charges::FilterChargeModelPropertiesService.call( | ||
charge:, properties: charge.properties | ||
).raise_if_error! | ||
charge.properties = result.properties | ||
charge.save! | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters