add createStakeOrder mutation
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
module Inputs
|
||||
class CreateStakeOrderAttributesInput < Types::BaseInputObject
|
||||
argument :currency_id, ID, required: true
|
||||
argument :pool_name, String, required: true
|
||||
argument :amount, String, "Amount to be paid", required: true
|
||||
end
|
||||
end
|
||||
31
app/graphql/mutations/create_stake_order.rb
Normal file
31
app/graphql/mutations/create_stake_order.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
module Mutations
|
||||
class CreateStakeOrder < BaseMutation
|
||||
field :order, Types::StakeOrderType, null: true
|
||||
|
||||
argument :order, Inputs::CreateStakeOrderAttributesInput, required: true
|
||||
|
||||
def resolve(order:)
|
||||
currency_id = decode_id(order[:currency_id])
|
||||
amount = BigDecimal(order[:amount])
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
current_user
|
||||
.balances
|
||||
.find_by!(currency_id: currency_id)
|
||||
.withdrawal!(amount)
|
||||
|
||||
record = StakeOrder.create!(
|
||||
amount: amount,
|
||||
currency_id: currency_id,
|
||||
pool_name: order[:pool_name],
|
||||
user_id: current_user.id,
|
||||
)
|
||||
|
||||
{ order: record }
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
{ errors: Resolvers::ModelErrors.from_active_record_model(e.record) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
module Types
|
||||
class MutationType < Types::BaseObject
|
||||
field :create_stake_order, mutation: Mutations::CreateStakeOrder
|
||||
field :create_sell_crypto_order, mutation: Mutations::CreateSellCryptoOrder
|
||||
field :create_buy_crypto_order, mutation: Mutations::CreateBuyCryptoOrder
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user