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