From ebd6fccf2e9c980a7ef9e7617a755807b3fe7b6a Mon Sep 17 00:00:00 2001 From: Christopher Vollick <0@psycoti.ca> Date: Thu, 5 May 2022 16:41:09 -0400 Subject: [PATCH] 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. --- lib/admin_command.rb | 25 ++++++++++++++----------- sgx_jmp.rb | 12 +++++++----- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/admin_command.rb b/lib/admin_command.rb index c408998..7d8a47a 100644 --- a/lib/admin_command.rb +++ b/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 diff --git a/sgx_jmp.rb b/sgx_jmp.rb index be6cbf6..763e025 100644 --- a/sgx_jmp.rb +++ b/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)) -- 2.34.2