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.7.24 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.23 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.22 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.21 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.20 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.19 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.18 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.17 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.16 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.15 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.14 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.13 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.12 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.4 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.2 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.1 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.7.0 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.6.4 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.6.3 lib/eco/api/microcases/preserve_policy_groups.rb
eco-helpers-2.6.2 lib/eco/api/microcases/preserve_policy_groups.rb