Sha256: 983d8a74405009c848b8c58639d125a5ea1b449f57329e0005b58d9a33fe35b3

Contents?: true

Size: 1001 Bytes

Versions: 8

Compression:

Stored size: 1001 Bytes

Contents

# frozen_string_literal: true

module Osso
  module GraphQL
    module Mutations
      class CreateEnterpriseAccount < BaseMutation
        null false

        argument :domain, String, required: true
        argument :name, String, required: true
        argument :oauth_client_id, String, required: false

        field :enterprise_account, Types::EnterpriseAccount, null: false
        field :errors, [String], null: false

        def resolve(**args)
          enterprise_account = Osso::Models::EnterpriseAccount.new(args)
          enterprise_account.oauth_client_id ||= find_client_db_id(context[:oauth_client_id])

          return response_data(enterprise_account: enterprise_account) if enterprise_account.save

          response_error(errors: enterprise_account.errors.full_messages)
        end

        def find_client_db_id(oauth_client_identifier)
          Osso::Models::OauthClient.find_by(identifier: oauth_client_identifier).
            id
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
osso-0.0.3.26 lib/osso/graphql/mutations/create_enterprise_account.rb
osso-0.0.3.25 lib/osso/graphql/mutations/create_enterprise_account.rb
osso-0.0.3.24 lib/osso/graphql/mutations/create_enterprise_account.rb
osso-0.0.3.23 lib/osso/graphql/mutations/create_enterprise_account.rb
osso-0.0.3.22 lib/osso/graphql/mutations/create_enterprise_account.rb
osso-0.0.3.21 lib/osso/graphql/mutations/create_enterprise_account.rb
osso-0.0.3.20 lib/osso/graphql/mutations/create_enterprise_account.rb
osso-0.0.3.19 lib/osso/graphql/mutations/create_enterprise_account.rb