lib/eco/api/usecases/default_cases/create_case.rb in eco-helpers-1.0.5 vs lib/eco/api/usecases/default_cases/create_case.rb in eco-helpers-1.0.6
- old
+ new
@@ -5,10 +5,11 @@
class CreateCase < DefaultCase
def process
@cases.define("create", type: :sync) do |entries, people, session, options, usecase|
creation = session.job_group("main").new("create", usecase: usecase, type: :create, sets: [:core, :details, :account])
+ supers = session.job_group("post").new("supers", usecase: usecase, type: :update, sets: :core)
strict_search = session.config.people.strict_search? && (!options[:search]&.key?(:strict) || options.dig(:search, :strict))
pgs = session.policy_groups
entries.each.with_index do |entry, i|
@@ -53,9 +54,26 @@
person.account.default_tag = tags.first unless tags.length > 1
end
end
creation.add(person)
+
+ # set supervisor
+ unless options.dig(:exclude, :core) || options.dig(:exclude, :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.supervisor_id = sup_id
+ end
+ end
+ end
+ end
+
end
end
end
end