debian-mirror-gitlab/app/services/customer_relations/contacts/create_service.rb
2022-07-17 14:43:12 +02:00

23 lines
599 B
Ruby

# frozen_string_literal: true
module CustomerRelations
module Contacts
class CreateService < BaseService
def execute
return error_no_permissions unless allowed?
return error_organization_invalid unless organization_valid?
contact = Contact.create(params.merge(group_id: group.id))
return error_creating(contact) unless contact.persisted?
ServiceResponse.success(payload: contact)
end
private
def error_creating(contact)
error(contact&.errors&.full_messages || 'Failed to create contact')
end
end
end
end