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

module UserPreferences
  class UpdateService < BaseService
    def initialize(user, params = {})
      @preferences = user.user_preference
      @params = params.to_h.dup.with_indifferent_access
    end

    def execute
      if @preferences.update(@params)
        ServiceResponse.success(
          message: 'Preference was updated',
          payload: { preferences: @preferences })
      else
        ServiceResponse.error(message: 'Could not update preference')
      end
    end
  end
end