~singpolyma/sgx-jmp

ref: 8dd92b96258d14d431e9966d0534631c7fdc0214 sgx-jmp/lib/admin_actions/reset_declines.rb -rw-r--r-- 1.1 KiB
8dd92b96Stephen Paul Weber Merge branch 'admin-actions' 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

require "value_semantics/monkey_patched"
require_relative "../admin_action"

class AdminAction
	class ResetDeclines < AdminAction
		class Command
			def self.for(target_customer, **)
				target_customer.declines.then { |declines|
					AdminAction::ResetDeclines.for(
						customer_id: target_customer.customer_id,
						previous_value: declines
					)
				}
			end
		end

		def customer_id
			@attributes[:customer_id]
		end

		def previous_value
			@attributes[:previous_value].to_i
		end

		def forward
			CustomerFinancials.new(customer_id).set_declines(0).then { self }
		end

		# I could make sure here that they're still set to 0 in the reverse case, so
		# I know there haven't been any declines since I ran the command, but I
		# think I don't care actually, and I should just set it back to what it was
		# and trust the human knows what they're doing
		def reverse
			CustomerFinancials.new(customer_id).set_declines(previous_value)
				.then { self }
		end

		def to_s
			"reset_declines(#{customer_id}): #{previous_value} -> 0"
		end
	end
end