Sha256: 65582187866485c194986c2029d57c22adca65b241d1239130246cf6f5d57709

Contents?: true

Size: 1.17 KB

Versions: 109

Compression:

Stored size: 1.17 KB

Contents

class Eco::API::UseCases::DefaultCases::ChangeEMailCase < Eco::API::Common::Loaders::UseCase
  name "change-email"
  type :sync
  
  # Target people with non-up-to-date emails will be updated to the new email
  def main(entries, people, session, options, usecase)
    micro    = session.micro
    remove   = session.new_job("main", "remove account", :update, usecase, :account)
    change   = session.new_job("main", "change email",   :update, usecase, :core)
    invite   = session.new_job("post", "add account",    :update, usecase, [:core, :account])

    micro.with_each_present(entries, people, options, log_starter: true) do |entry, person|
      if entry.email != person.email
        super_id      = person.supervisor_id
        s_account_doc = person.account&.doc
        account_doc   = s_account_doc ? JSON.parse(s_account_doc.to_json) : nil

        remove.add(person) {|person| person.account = nil        }
        change.add(person) {|person| person.email   = entry.email}
        invite.add(person) do |person|
          person.account       = account_doc if account_doc
          person.supervisor_id = super_id
        end
      end
    end
  end

end

Version data entries

109 entries across 109 versions & 1 rubygems

Version Path
eco-helpers-2.5.2 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.5.1 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.4.9 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.4.8 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.4.7 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.4.6 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.4.5 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.4.4 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.4.3 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.4.2 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.3.3 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.3.2 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.2.5 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.2.4 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.2.3 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.2.2 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.2.1 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.1.12 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.1.11 lib/eco/api/usecases/default_cases/change_email_case.rb
eco-helpers-2.1.10 lib/eco/api/usecases/default_cases/change_email_case.rb