add create sell and buy crypto order mutations

This commit is contained in:
João Geonizeli
2021-08-15 01:59:59 -03:00
parent 4b1341677f
commit a3d32ee13a
25 changed files with 688 additions and 15 deletions

View File

@@ -0,0 +1,22 @@
# frozen_string_literal: true
module Types
class BuyCryptoOrderType < Types::BaseObject
implements GraphQL::Types::Relay::Node
global_id_field :id
graphql_name "BuyCryptoOrder"
field :id, ID, null: false
field :currency, CurrencyType, null: false
def currency
dataloader.with(Dataloader::Source, Currency).load(object.currency_id)
end
field :status, ProcessStatusEnum, null: false
field :paid_amount_cents, Integer, null: false
field :received_amount, String, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
end
end

View File

@@ -9,7 +9,5 @@ module Types
field :id, ID, null: false
field :amount_cents, Integer, null: false
field :amount_currency, String, null: false
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
end
end

View File

@@ -1,5 +1,7 @@
# frozen_string_literal: true
module Types
class MutationType < Types::BaseObject
field :create_sell_crypto_order, mutation: Mutations::CreateSellCryptoOrder
field :create_buy_crypto_order, mutation: Mutations::CreateBuyCryptoOrder
end
end

View File

@@ -0,0 +1,10 @@
# frozen_string_literal: true
module Types
class ProcessStatusEnum < Types::BaseEnum
graphql_name "ProcessStatus"
value "PROCESSING", value: "processing"
value "COMPLETED", value: "completed"
value "CANCELED", value: "canceled"
end
end

View File

@@ -18,5 +18,15 @@ module Types
def fiat_balances
Pundit.policy_scope(current_user, FiatBalance)
end
field :sell_crypto_orders, SellCryptoOrderType.connection_type, null: false
def sell_crypto_orders
[]
end
field :buy_crypto_orders, BuyCryptoOrderType.connection_type, null: false
def buy_crypto_orders
[]
end
end
end

View File

@@ -0,0 +1,11 @@
# frozen_string_literal: true
module Types
class RecordInvalidType < Types::BaseObject
graphql_name "RecordInvalid"
field :full_messages, [String], null: false
field :field_name, String, null: true
field :messages, [String], null: true
field :path, [String], null: true
end
end

View File

@@ -0,0 +1,22 @@
# frozen_string_literal: true
module Types
class SellCryptoOrderType < Types::BaseObject
implements GraphQL::Types::Relay::Node
global_id_field :id
graphql_name "SellCryptoOrder"
field :id, ID, null: false
field :currency, CurrencyType, null: false
def currency
dataloader.with(Dataloader::Source, Currency).load(object.currency_id)
end
field :status, ProcessStatusEnum, null: false
field :paid_amount, String, null: false
field :received_amount_cents, Integer, null: true
field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false
end
end