Module: Eco::API::MicroCases::People::Preserve::PolicyGroups

Included in:
Eco::API::MicroCases::People::Preserve
Defined in:
lib/eco/api/microcases/people/preserve/policy_groups.rb

Instance Method Summary collapse

Instance Method Details

#preserve_policy_groups(person, _options, keep_new: false) ⇒ String

Note:
  1. It only works if the original value of policy_group_ids was not empty

Helper to preserve the original policy_group_ids.

Parameters:

  • person (Ecoportal::API::V1::Person)

    the person we want to update, carrying the changes to be done.

  • options (Hash)

    the options.

  • keep_new (Boolean) (defaults to: false)

    tells if it should keep the new policy groups or get rid of them.

Returns:

  • (String)

    the final value of policy_group_ids.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/eco/api/microcases/people/preserve/policy_groups.rb', line 14

def preserve_policy_groups(person, _options, keep_new: false)
  return unless ( = person.)

  .policy_group_ids.tap do
    next unless .as_update.key?('policy_group_ids')
    next unless (original = person.original_doc.dig('account', 'policy_group_ids'))
    next if original.empty?

    if keep_new
      person..policy_group_ids += original
    else
      person..policy_group_ids  = original
    end

    return .policy_group_ids
  end
end