Sha256: 073b18de8e12224d4b4076109524cbcb062a856116d6a911e0700fe1bdc6bbac

Contents?: true

Size: 1.96 KB

Versions: 43

Compression:

Stored size: 1.96 KB

Contents

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

          def process
            @cases.define("change-email", type: :sync) do |entries, people, session, options, usecase|
              remove      = session.job_group("main").new("remove account", usecase: usecase, type: :update, sets: :account)
              change      = session.job_group("main").new("change email", usecase: usecase, type: :update, sets: :core)
              add_account = session.job_group("post").new("add account", usecase: usecase, type: :update, sets: :account)

              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
                  unless entry.email.to_s.strip.downcase == person.email.to_s.strip.downcase

                    super_id      = person.supervisor_id
                    s_account_doc = person.account&.doc
                    account_doc   = s_account_doc ? JSON.parse(s_account_doc.to_json) : nil

                    person.account = nil
                    remove.add(person)

                    new_email = entry.email
                    change.add(person) do |person|
                      person.email = new_email
                    end

                    add_account.add(person) do |person|
                      if account_doc
                        person.account = account_doc
                      end
                      person.supervisor_id = super_id
                    end
                  end

                end
              end
            end
          end

        end
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

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