module Eco module API module UseCases class DefaultCases class UpsertAccountCase < BaseCase def process @cases.define("upsert-account", type: :sync) do |entries, people, session, options| creation = session.job_group("main").new("create", type: :create, sets: [:core, :account]) update = session.job_group("main").new("update", type: :update, sets: [:core, :account]) entries.each.with_index do |entry, i| create = false unless person = people.find(entry) create = true person = session.new_person entry.set_core(person) #entry.set_details(person) end entry.set_account(person) person.account.permissions_custom = session.new_preset(person) person.account.send_invites = false if options.key?(:send_invites) && !options(:send_invites) creation.add(person) if create update.add(person) unless create end end end end end end end end