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