debian-mirror-gitlab/app/services/customer_relations/contacts/update_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

31 lines
750 B
Ruby
Raw Normal View History

2021-11-18 22:05:49 +05:30
# frozen_string_literal: true
module CustomerRelations
module Contacts
class UpdateService < BaseService
def execute(contact)
return error_no_permissions unless allowed?
2022-07-16 23:28:13 +05:30
handle_active_param
return error_organization_invalid unless organization_valid?
2021-11-18 22:05:49 +05:30
return error_updating(contact) unless contact.update(params)
ServiceResponse.success(payload: contact)
end
private
2022-07-16 23:28:13 +05:30
def handle_active_param
return if params[:active].nil?
active = params.delete(:active)
params[:state] = active ? 'active' : 'inactive'
2021-11-18 22:05:49 +05:30
end
def error_updating(contact)
error(contact&.errors&.full_messages || 'Failed to update contact')
end
end
end
end