diff options
Diffstat (limited to 'app/services/customer_relations/organizations/create_service.rb')
-rw-r--r-- | app/services/customer_relations/organizations/create_service.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/services/customer_relations/organizations/create_service.rb b/app/services/customer_relations/organizations/create_service.rb new file mode 100644 index 00000000000..9c223796eaf --- /dev/null +++ b/app/services/customer_relations/organizations/create_service.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module CustomerRelations + module Organizations + class CreateService < BaseService + # returns the created organization + def execute + return error_no_permissions unless allowed? + + params[:group_id] = group.id + + organization = Organization.create(params) + + return error_creating(organization) unless organization.persisted? + + ServiceResponse.success(payload: organization) + end + + private + + def error_no_permissions + error('You have insufficient permissions to create an organization for this group') + end + + def error_creating(organization) + error(organization&.errors&.full_messages || 'Failed to create organization') + end + end + end +end |