Class: Eco::API::UseCases::DefaultCases::SwitchSupervisorCase
- Inherits:
-
Eco::API::UseCases::DefaultCase
- Object
- Eco::API::UseCases::DefaultCase
- Eco::API::UseCases::DefaultCases::SwitchSupervisorCase
- Defined in:
- lib/eco/api/usecases/default_cases/switch_supervisor_case.rb
Instance Method Summary collapse
Methods inherited from Eco::API::UseCases::DefaultCase
Constructor Details
This class inherits a constructor from Eco::API::UseCases::DefaultCase
Instance Method Details
#process ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/eco/api/usecases/default_cases/switch_supervisor_case.rb', line 7 def process @cases.define("switch-supervisor", type: :transform) do |people, session, , usecase| unless old_id = .dig(:super, :old) msg = "You haven't specified the original supervisor. Aborting..." session.logger.error(msg) exit(1) end # we could be setting the supervisor to nil unless [:super].key?(:new) msg = "You haven't specified the new supervisor. Aborting..." session.logger.error(msg) exit(1) end new_id = .dig(:super, :new) unless old_sup = people.person(id: old_id, external_id: old_id, email: old_id) msg = "Couldn't find any user with that id (old-super): '#{old_id}'. Aborting..." session.logger.error(msg) exit(1) end unless new_sup = people.person(id: new_id, external_id: new_id, email: new_id) msg = "Couldn't find any user with that id (new-super): '#{new_id}'. Aborting..." session.logger.error(msg) exit(1) end people = people.supervisor_id(old_sup.id) unless people.length > 0 msg = "There are no people with supervisor #{old_sup.external_id} (#{old_sup.name} - #{old_sup.email}). Aborting..." session.logger.error(msg) exit(1) end session.logger.info("Going to change supervisor '#{old_sup.name}' (#{old_sup.external_id}) to '#{new_sup.name}' (#{new_sup.external_id})") # create batch queue supers = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :core) people.each.with_index do |person, i| person.supervisor_id = new_sup.id supers.add(person) end end end |