add createStakeRemoveMutation
This commit is contained in:
29
app/graphql/mutations/create_stake_remove_order.rb
Normal file
29
app/graphql/mutations/create_stake_remove_order.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
33
app/javascript/__generated__/schema.graphql
generated
33
app/javascript/__generated__/schema.graphql
generated
@@ -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
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user