Sha256: 4bd94ccb0469e2998cb2daa8172c3144cb41894caf0c7a9a3ee1784ee886882e

Contents?: true

Size: 903 Bytes

Versions: 7

Compression:

Stored size: 903 Bytes

Contents

# frozen_string_literal: true

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

        argument :id, ID, required: true

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

        def resolve(id:)
          enterprise_account = Osso::Models::EnterpriseAccount.find(id)

          return response_data(enterprise_account: nil) if enterprise_account.destroy

          response_error(errors: enterprise_account.errors.full_messages)
        end

        def ready?(id:)
          return true if context[:scope] == :admin

          domain = account_domain(id)

          return true if domain == context[:scope]

          raise ::GraphQL::ExecutionError, "This user lacks the scope to mutate records belonging to #{domain}"
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
osso-0.0.3.16 lib/osso/graphql/mutations/delete_enterprise_account.rb
osso-0.0.3.15 lib/osso/graphql/mutations/delete_enterprise_account.rb
osso-0.0.3.14 lib/osso/graphql/mutations/delete_enterprise_account.rb
osso-0.0.3.13 lib/osso/graphql/mutations/delete_enterprise_account.rb
osso-0.0.3.12 lib/osso/graphql/mutations/delete_enterprise_account.rb
osso-0.0.3.11 lib/osso/graphql/mutations/delete_enterprise_account.rb
osso-0.0.3.9 lib/osso/graphql/mutations/delete_enterprise_account.rb