summaryrefslogtreecommitdiff
path: root/app/services/labels/update_service.rb
blob: be33947d0eb360f9df39cf7a78a0f5c03012e96b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# frozen_string_literal: true

module Labels
  class UpdateService < Labels::BaseService
    def initialize(params = {})
      @params = params.to_h.dup.with_indifferent_access
    end

    # returns the updated label
    def execute(label)
      params[:name] = params.delete(:new_name) if params.key?(:new_name)
      params[:color] = convert_color_name_to_hex if params[:color].present?

      label.update(params)
      label
    end
  end
end