Sha256: da4dddf4aaf921af3a4db222eeb5466eb97053ebe1042bd00fb585f2b7f8242d

Contents?: true

Size: 1.13 KB

Versions: 36

Compression:

Stored size: 1.13 KB

Contents

class Eco::API::UseCases::Default::People::Utils::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)
    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, %i[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) {|pers| pers.account = nil         }
        change.add(person) {|pers| pers.email   = entry.email }
        invite.add(person) do |pers|
          pers.account       = account_doc if account_doc
          pers.supervisor_id = super_id
        end
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.20 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.19 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.18 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.17 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.16 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.15 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.14 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.13 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.12 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.11 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.10 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.9 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.8 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.7 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.6 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.5 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.4 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.3 lib/eco/api/usecases/default/people/utils/change_email_case.rb
eco-helpers-3.0.2 lib/eco/api/usecases/default/people/utils/change_email_case.rb