add createDepositOrder mutation
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
module Inputs
|
||||||
|
class CreateDepositOrderAttributesInput < Types::BaseInputObject
|
||||||
|
argument :amount_cents, Integer, "Amount to be paid", required: true
|
||||||
|
end
|
||||||
|
end
|
||||||
19
app/graphql/mutations/create_deposit_order.rb
Normal file
19
app/graphql/mutations/create_deposit_order.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
module Mutations
|
||||||
|
class CreateDepositOrder < BaseMutation
|
||||||
|
field :order, Types::DepositOrderType, null: true
|
||||||
|
|
||||||
|
argument :order, Inputs::CreateStakeOrderAttributesInput, required: true
|
||||||
|
|
||||||
|
def resolve(order:)
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
record = BuildDepositOrder.new(paid_amount_cents: order[:amount_cents], user: current_user.id)
|
||||||
|
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
|
# frozen_string_literal: true
|
||||||
module Types
|
module Types
|
||||||
class MutationType < Types::BaseObject
|
class MutationType < Types::BaseObject
|
||||||
|
field :create_deposit_order, mutation: Mutations::CreateDepositOrder
|
||||||
field :create_stake_remove_order, mutation: Mutations::CreateStakeRemoveOrder
|
field :create_stake_remove_order, mutation: Mutations::CreateStakeRemoveOrder
|
||||||
field :create_stake_order, mutation: Mutations::CreateStakeOrder
|
field :create_stake_order, mutation: Mutations::CreateStakeOrder
|
||||||
field :create_sell_crypto_order, mutation: Mutations::CreateSellCryptoOrder
|
field :create_sell_crypto_order, mutation: Mutations::CreateSellCryptoOrder
|
||||||
|
|||||||
33
app/javascript/__generated__/schema.graphql
generated
33
app/javascript/__generated__/schema.graphql
generated
@@ -76,6 +76,33 @@ type CreateBuyCryptoOrderPayload {
|
|||||||
order: BuyCryptoOrder
|
order: BuyCryptoOrder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
Autogenerated input type of CreateDepositOrder
|
||||||
|
"""
|
||||||
|
input CreateDepositOrderInput {
|
||||||
|
"""
|
||||||
|
A unique identifier for the client performing the mutation.
|
||||||
|
"""
|
||||||
|
clientMutationId: String
|
||||||
|
order: CreateStakeOrderAttributesInput!
|
||||||
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
Autogenerated return type of CreateDepositOrder
|
||||||
|
"""
|
||||||
|
type CreateDepositOrderPayload {
|
||||||
|
"""
|
||||||
|
A unique identifier for the client performing the mutation.
|
||||||
|
"""
|
||||||
|
clientMutationId: String
|
||||||
|
|
||||||
|
"""
|
||||||
|
Errors encountered during execution of the mutation.
|
||||||
|
"""
|
||||||
|
errors: [RecordInvalid!]
|
||||||
|
order: DepositOrder
|
||||||
|
}
|
||||||
|
|
||||||
input CreateSellCryptoOrderAttributesInput {
|
input CreateSellCryptoOrderAttributesInput {
|
||||||
"""
|
"""
|
||||||
Amount to be paid
|
Amount to be paid
|
||||||
@@ -233,6 +260,12 @@ type Mutation {
|
|||||||
"""
|
"""
|
||||||
input: CreateBuyCryptoOrderInput!
|
input: CreateBuyCryptoOrderInput!
|
||||||
): CreateBuyCryptoOrderPayload
|
): CreateBuyCryptoOrderPayload
|
||||||
|
createDepositOrder(
|
||||||
|
"""
|
||||||
|
Parameters for CreateDepositOrder
|
||||||
|
"""
|
||||||
|
input: CreateDepositOrderInput!
|
||||||
|
): CreateDepositOrderPayload
|
||||||
createSellCryptoOrder(
|
createSellCryptoOrder(
|
||||||
"""
|
"""
|
||||||
Parameters for CreateSellCryptoOrder
|
Parameters for CreateSellCryptoOrder
|
||||||
|
|||||||
19
app/services/build_deposit_order.rb
Normal file
19
app/services/build_deposit_order.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
class BuildDepositOrder
|
||||||
|
DEPOSIT_FEE = 0.05
|
||||||
|
|
||||||
|
attr_reader :paid_amount_cents, :user_id
|
||||||
|
|
||||||
|
def initilize(paid_amount_cents:, user_id:)
|
||||||
|
@paid_amount_cents = paid_amount_cents
|
||||||
|
@user_id = user_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def build
|
||||||
|
DepositOrder.new(
|
||||||
|
user_id: user_id,
|
||||||
|
paid_amount_cents: paid_amount_cents,
|
||||||
|
received_amount_cents: paid_amount_cents + (paid_amount_cents * DEPOSIT_FEE)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user