1# frozen_string_literal: true
2
3require_relative "sim_order"
4
5class EditSimNicknames
6 include SIMAction
7
8 # @param [Customer] customer the customer editing the sims
9 # @param [Array<Sim>] sims the sims whose nicknames
10 # are up for editing
11 def initialize(customer, sims, sim_repo: SIMRepo.new(db: DB))
12 @customer = customer
13 @sims = sims
14 @sim_repo = sim_repo
15 end
16
17 def form
18 FormTemplate.render(
19 "edit_sim_nicknames",
20 sims: @sims
21 )
22 end
23
24 def complete(iq)
25 EMPromise.resolve(nil).then {
26 sims = @sims.map { |sim|
27 sim.with(nickname: iq.form.field("sim-#{sim.iccid}").value)
28 }
29 @sim_repo.update_nicknames(sims)
30 }.then {
31 Command.finish("Successfully updated SIM nicknames.")
32 }
33 end
34end