Refetch Customer on Repeated Customer Info Calls

Christopher Vollick created

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.

Change summary

lib/admin_command.rb | 25 ++++++++++++++-----------
sgx_jmp.rb           | 12 +++++++-----
2 files changed, 21 insertions(+), 16 deletions(-)

Detailed changes

lib/admin_command.rb 🔗

@@ -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

sgx_jmp.rb 🔗

@@ -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))