lib/eco/api/microcases/people_refresh.rb in eco-helpers-2.0.41 vs lib/eco/api/microcases/people_refresh.rb in eco-helpers-2.0.42
- old
+ new
@@ -1,17 +1,24 @@
module Eco
module API
class MicroCases
# Helper to obtain all the elements of `people` anew from the _People Manager_.
- # @note this helper is normally used to run consecutive usecases, where data needs refresh.
+ # @note
+ # 1. This helper is normally used to run consecutive usecases, where data needs refresh.
+ # 2. It only includes new people if they are not dirty (they do not have pending updates)
+ # - This contingency wouldn't be necessary if the server worked perfectly.
# @param people [Eco::API::Organization::People] the people that needs refresh.
# @param include_created [Boolean] include people created during this session? (will check `:create` batch jobs).
# @return [Eco::API::Organization::People] the `People` object with the data.
def people_refresh(people:, include_created: true)
+ people = people.newFrom people.select do |person|
+ !person.new? || !person.dirty?
+ end
ini = people.length
if include_created
session.job_groups.find_jobs(type: :create).map do |job|
- people = people.merge(job.people)
+ to_add = job.people.select {|person| !person.dirty?}
+ people = people.merge(to_add)
end
end
created = people.length - ini
msg = "Going to refresh #{people.length} people with server data"