add DepositOrder model and query
This commit is contained in:
16
app/graphql/types/deposit_order_type.rb
Normal file
16
app/graphql/types/deposit_order_type.rb
Normal file
@@ -0,0 +1,16 @@
|
||||
# frozen_string_literal: true
|
||||
module Types
|
||||
class DepositOrderType < Types::BaseObject
|
||||
implements GraphQL::Types::Relay::Node
|
||||
global_id_field :id
|
||||
|
||||
graphql_name "DepositOrder"
|
||||
|
||||
field :id, ID, null: false
|
||||
field :status, String, null: false
|
||||
field :received_amount_cents, Integer, null: false
|
||||
field :paid_amount_cents, Integer, null: false
|
||||
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
|
||||
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
|
||||
end
|
||||
end
|
||||
@@ -31,5 +31,10 @@ module Types
|
||||
|
||||
ransack(scope, filter)
|
||||
end
|
||||
|
||||
field :deposit_orders, DepositOrderType.connection_type, null: false
|
||||
def deposit_orders
|
||||
Pundit.policy_scope(current_user, DepositOrder)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,6 +14,8 @@ class XStakeSchema < GraphQL::Schema
|
||||
Types::SellCryptoOrderType
|
||||
when BuyCryptoOrder
|
||||
Types::BuyCryptoOrderType
|
||||
when DepositOrder
|
||||
Types::DepositOrderType
|
||||
else
|
||||
raise(GraphQL::RequiredImplementationMissingError, "Unexpected object: #{obj}")
|
||||
end
|
||||
|
||||
60
app/javascript/__generated__/schema.graphql
generated
60
app/javascript/__generated__/schema.graphql
generated
@@ -172,6 +172,45 @@ type CreateStakeRemoveOrderPayload {
|
||||
order: StakeOrder
|
||||
}
|
||||
|
||||
type DepositOrder implements Node {
|
||||
createdAt: ISO8601DateTime!
|
||||
id: ID!
|
||||
paidAmountCents: Int!
|
||||
receivedAmountCents: Int!
|
||||
status: String!
|
||||
updatedAt: ISO8601DateTime!
|
||||
}
|
||||
|
||||
"""
|
||||
The connection type for DepositOrder.
|
||||
"""
|
||||
type DepositOrderConnection {
|
||||
"""
|
||||
A list of edges.
|
||||
"""
|
||||
edges: [DepositOrderEdge!]!
|
||||
|
||||
"""
|
||||
Information to aid in pagination.
|
||||
"""
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
"""
|
||||
An edge in a connection.
|
||||
"""
|
||||
type DepositOrderEdge {
|
||||
"""
|
||||
A cursor for use in pagination.
|
||||
"""
|
||||
cursor: String!
|
||||
|
||||
"""
|
||||
The item at the end of the edge.
|
||||
"""
|
||||
node: DepositOrder!
|
||||
}
|
||||
|
||||
type FiatBalance implements Node {
|
||||
amountCents: Int!
|
||||
amountCurrency: String!
|
||||
@@ -286,6 +325,27 @@ type Query {
|
||||
last: Int
|
||||
): BuyCryptoOrderConnection!
|
||||
currentUser: User
|
||||
depositOrders(
|
||||
"""
|
||||
Returns the elements in the list that come after the specified cursor.
|
||||
"""
|
||||
after: String
|
||||
|
||||
"""
|
||||
Returns the elements in the list that come before the specified cursor.
|
||||
"""
|
||||
before: String
|
||||
|
||||
"""
|
||||
Returns the first _n_ elements from the list.
|
||||
"""
|
||||
first: Int
|
||||
|
||||
"""
|
||||
Returns the last _n_ elements from the list.
|
||||
"""
|
||||
last: Int
|
||||
): DepositOrderConnection!
|
||||
|
||||
"""
|
||||
Fetches an object given its ID.
|
||||
|
||||
31
app/models/deposit_order.rb
Normal file
31
app/models/deposit_order.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: deposit_orders
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# paid_amount_cents :integer default(0), not null
|
||||
# received_amount_cents :integer default(0), not null
|
||||
# status :string not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# user_id :bigint not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_deposit_orders_on_user_id (user_id)
|
||||
#
|
||||
# Foreign Keys
|
||||
#
|
||||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
class DepositOrder < ApplicationRecord
|
||||
include Processable
|
||||
include Trackable
|
||||
|
||||
belongs_to :user
|
||||
|
||||
monetize :paid_amount_cents
|
||||
monetize :received_amount_cents
|
||||
end
|
||||
10
app/policies/deposit_order_policy.rb
Normal file
10
app/policies/deposit_order_policy.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
class DepositOrderPolicy < ApplicationPolicy
|
||||
class Scope < Scope
|
||||
def resolve
|
||||
return scope.none if user.nil?
|
||||
|
||||
scope.where(user_id: user.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user