Sha256: 8b319d6c3279acbc426d11f393cdb4a7eed4046f382d1f698efdb4fcbab71ee5

Contents?: true

Size: 1.52 KB

Versions: 50

Compression:

Stored size: 1.52 KB

Contents

module Eco
  module API
    class UseCases
      class DefaultCases
        class SetSupervisorCase < DefaultCase

          def process
            @cases.define("set-supervisor", type: :sync) do |entries, people, session, options, usecase|
              job = session.job_group("main").new("update", usecase: usecase, type: :update, sets: :core)

              strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))

              entries.each.with_index do |entry, i|
                person = people.find(entry, strict: strict_search)

                if !person
                  session.logger.error("Entry(#{i}) - this person does not exist: #{entry.to_s(:identify)}")
                else
                  sup_id = entry.supervisor_id
                  supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id)

                  if !supervisor
                    if entry.supervisor_id
                      msg = "Entry(#{i}) - supervisor id #{entry.supervisor_id} does not exist for person: #{entry.to_s(:identify)}"
                      session.logger.warn(msg)
                    end
                  else
                    # set internal id of the supervisor (detect if actually changed)
                    person.supervisor_id = supervisor.id
                    job.add(person)
                  end
                end
              end
            end
          end

        end
      end
    end
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
eco-helpers-1.5.1 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.5.0 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.4.2 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.19 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.4.1 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.4.0 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.18 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.17 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.16 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.15 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.14 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.13 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.12 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.11 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.10 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.9 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.8 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.7 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.6 lib/eco/api/usecases/default_cases/set_supervisor_case.rb
eco-helpers-1.3.5 lib/eco/api/usecases/default_cases/set_supervisor_case.rb