module Eco module API module UseCases class DefaultCases class HrisCase < BaseCase def process @cases.define("hris", type: :sync) do |entries, people, session, options| # IMPORTANT: this two lines ensure that key users are preserved (only manually maintained) #people = people.exclude(session.discarded_entries) #entries = entries.exclude(session.discarded_entries) creation = session.job_group("main").new("create", type: :create, sets: [:core, :details, :account]) update = session.job_group("main").new("update", type: :update, sets: [:core, :details, :account]) supers = session.job_group("post").new("supers", type: :update, sets: :core) #remove = session.job_group("post").new("remove_account", type: :update, sets: :account) #people.users.each_with_index do |person, i| # if !entries.find(person) # remove.add(person) do |person| # person.account = nil # person # end # end #end entries.each.with_index do |entry, i| person = people.find(entry) person = session.new_person if create = !person entry.set_core(person, exclude: "supervisor_id") entry.set_details(person) entry.set_account(person) #if !remove.people.find(entry) person.account.permissions_custom = session.new_preset(person) person.account.default_tag = person.account.filter_tags.first if person.account.filter_tags.length == 1 creation.add(person) if create update.add(person) unless create # set supervisor if !(sup_id = entry.supervisor_id) person.supervisor_id = nil else if supervisor = people.person(id: sup_id, external_id: sup_id, email: sup_id) person.supervisor_id = supervisor.id else # delay setting supervisor if does not exit supers.add(person) do |person| #person = session.new_person(person: person.doc) person.sync person.supervisor_id = sup_id person end end end end end end end end end end end