add createStakeRemoveMutation

This commit is contained in:
João Geonizeli
2021-08-27 10:39:39 -03:00
parent e4bf220185
commit 3967e182cf
4 changed files with 183 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
# frozen_string_literal: true
module Mutations
class CreateStakeRemoveOrder < 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
record = StakeOrder.find_or_initialize_by(
pool_name: order[:pool_name],
user_id: current_user.id,
currency_id: currency_id,
status: :processing
)
record.amount += amount
record.save!
{ order: record }
rescue ActiveRecord::RecordInvalid => e
{ errors: Resolvers::ModelErrors.from_active_record_model(e.record) }
end
end
end
end

View File

@@ -1,6 +1,7 @@
# frozen_string_literal: true
module Types
class MutationType < Types::BaseObject
field :create_stake_remove_order, mutation: Mutations::CreateStakeRemoveOrder
field :create_stake_order, mutation: Mutations::CreateStakeOrder
field :create_sell_crypto_order, mutation: Mutations::CreateSellCryptoOrder
field :create_buy_crypto_order, mutation: Mutations::CreateBuyCryptoOrder

View File

@@ -180,6 +180,33 @@ type CreateStakeOrderPayload {
order: StakeOrder
}
"""
Autogenerated input type of CreateStakeRemoveOrder
"""
input CreateStakeRemoveOrderInput {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
order: CreateStakeOrderAttributesInput!
}
"""
Autogenerated return type of CreateStakeRemoveOrder
"""
type CreateStakeRemoveOrderPayload {
"""
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
"""
Errors encountered during execution of the mutation.
"""
errors: [RecordInvalid!]
order: StakeOrder
}
type Currency implements Node {
id: ID!
name: String!
@@ -245,6 +272,12 @@ type Mutation {
"""
input: CreateStakeOrderInput!
): CreateStakeOrderPayload
createStakeRemoveOrder(
"""
Parameters for CreateStakeRemoveOrder
"""
input: CreateStakeRemoveOrderInput!
): CreateStakeRemoveOrderPayload
}
"""