add DepositOrder model and query

This commit is contained in:
João Geonizeli
2021-09-05 21:21:10 -03:00
parent bb69836c6c
commit c4e6807d61
11 changed files with 328 additions and 97 deletions

View 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

View File

@@ -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

View File

@@ -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

View File

@@ -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.

View 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

View 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