~singpolyma/sgx-jmp

ebd6fccf2e9c980a7ef9e7617a755807b3fe7b6a — Christopher Vollick 4 months ago 8041a50
Refetch Customer on Repeated Customer Info Calls

This means if I fetch a user, make a change (add a transaction, set
their trust level, etc), I can re-run info from the menu to get the same
user with up-to-date info, so you can see the thing I just did reflected
back to me.
2 files changed, 21 insertions(+), 16 deletions(-)

M lib/admin_command.rb
M sgx_jmp.rb
M lib/admin_command.rb => lib/admin_command.rb +14 -11
@@ 6,12 6,15 @@ require_relative "financial_info"
require_relative "form_template"

class AdminCommand
	def initialize(target_customer)
	def initialize(target_customer, customer_repo)
		@target_customer = target_customer
		@customer_repo = customer_repo
	end

	def start
		action_info.then { menu_or_done }
		@target_customer.admin_info.then { |info|
			reply(info.form)
		}.then { menu_or_done }
	end

	def reply(form)


@@ 40,19 43,19 @@ class AdminCommand
	end

	def new_context(q)
		CustomerInfoForm.new.parse_something(q).then do |new_customer|
			if new_customer.respond_to?(:customer_id)
				AdminCommand.new(new_customer).start
			else
				reply(new_customer.form)
		CustomerInfoForm.new(@customer_repo)
			.parse_something(q).then do |new_customer|
				if new_customer.respond_to?(:customer_id)
					AdminCommand.new(new_customer, @customer_repo).start
				else
					reply(new_customer.form)
				end
			end
		end
	end

	def action_info
		@target_customer.admin_info.then do |info|
			reply(info.form)
		end
		# Refresh the data
		new_context(@target_customer.customer_id)
	end

	def action_financial

M sgx_jmp.rb => sgx_jmp.rb +7 -5
@@ 755,16 755,18 @@ Command.new(
	Command.customer.then do |customer|
		raise AuthError, "You are not an admin" unless customer&.admin?

		customer_repo = CustomerRepo.new(
			sgx_repo: Bwmsgsv2Repo.new,
			bandwidth_tn_repo: EmptyRepo.new # No CNAM in admin
		)

		Command.reply { |reply|
			reply.allowed_actions = [:next]
			reply.command << FormTemplate.render("customer_picker")
		}.then { |response|
			CustomerInfoForm.new(CustomerRepo.new(
				sgx_repo: Bwmsgsv2Repo.new,
				bandwidth_tn_repo: EmptyRepo.new # No CNAM in admin
			)).find_customer(response)
			CustomerInfoForm.new(customer_repo).find_customer(response)
		}.then do |target_customer|
			AdminCommand.new(target_customer).start
			AdminCommand.new(target_customer, customer_repo).start
		end
	end
}.register(self).then(&CommandList.method(:register))