Sha256: c036d552f0ffee21af8a1bdc5906c20668b31bfdfbf874380440ec77ec700bd8

Contents?: true

Size: 1.13 KB

Versions: 110

Compression:

Stored size: 1.13 KB

Contents

module Eco
  module API
    class MicroCases
      # Helper to preserve the original `policy_group_ids`.
      # @note
      #   1. It only works if the original value of `policy_group_ids` was **not** empty
      # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
      # @param options [Hash] the options.
      # @param keep_new [Boolean] tells if it should keep the new policy groups or get rid of them.
      # @return [String] the final value of `policy_group_ids`.
      def preserve_policy_groups(person, options, keep_new: false)
        if account = person.account
          if account.as_update.key?("policy_group_ids")
            if original = person.original_doc.dig("account", "policy_group_ids")
              unless original.empty?
                if keep_new
                  person.account.policy_group_ids += original
                else
                  person.account.policy_group_ids  = original
                end
              end
            end
          end
        end
        person.account&.policy_group_ids
      end

    end
  end
end

Version data entries

110 entries across 110 versions & 1 rubygems

Version Path
eco-helpers-2.0.67 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.66 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.65 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.64 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.63 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.62 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.61 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.60 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.59 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.58 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.57 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.56 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.55 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.54 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.53 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.52 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.51 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.50 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.49 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.0.48 lib/eco/api/microcases/preserve_policy_groups.rb