diff --git a/app/graphql/types/deposit_order_type.rb b/app/graphql/types/deposit_order_type.rb new file mode 100644 index 0000000..e0ae3bd --- /dev/null +++ b/app/graphql/types/deposit_order_type.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true +module Types + class DepositOrderType < Types::BaseObject + implements GraphQL::Types::Relay::Node + global_id_field :id + + graphql_name "DepositOrder" + + field :id, ID, null: false + field :status, String, null: false + field :received_amount_cents, Integer, null: false + field :paid_amount_cents, Integer, null: false + field :created_at, GraphQL::Types::ISO8601DateTime, null: false + field :updated_at, GraphQL::Types::ISO8601DateTime, null: false + end +end diff --git a/app/graphql/types/query_type.rb b/app/graphql/types/query_type.rb index ff4b89b..9d41d4f 100644 --- a/app/graphql/types/query_type.rb +++ b/app/graphql/types/query_type.rb @@ -31,5 +31,10 @@ module Types ransack(scope, filter) end + + field :deposit_orders, DepositOrderType.connection_type, null: false + def deposit_orders + Pundit.policy_scope(current_user, DepositOrder) + end end end diff --git a/app/graphql/x_stake_schema.rb b/app/graphql/x_stake_schema.rb index 268a968..bca4b1f 100644 --- a/app/graphql/x_stake_schema.rb +++ b/app/graphql/x_stake_schema.rb @@ -14,6 +14,8 @@ class XStakeSchema < GraphQL::Schema Types::SellCryptoOrderType when BuyCryptoOrder Types::BuyCryptoOrderType + when DepositOrder + Types::DepositOrderType else raise(GraphQL::RequiredImplementationMissingError, "Unexpected object: #{obj}") end diff --git a/app/javascript/__generated__/schema.graphql b/app/javascript/__generated__/schema.graphql index 878a20c..29a8a31 100644 --- a/app/javascript/__generated__/schema.graphql +++ b/app/javascript/__generated__/schema.graphql @@ -172,6 +172,45 @@ type CreateStakeRemoveOrderPayload { order: StakeOrder } +type DepositOrder implements Node { + createdAt: ISO8601DateTime! + id: ID! + paidAmountCents: Int! + receivedAmountCents: Int! + status: String! + updatedAt: ISO8601DateTime! +} + +""" +The connection type for DepositOrder. +""" +type DepositOrderConnection { + """ + A list of edges. + """ + edges: [DepositOrderEdge!]! + + """ + Information to aid in pagination. + """ + pageInfo: PageInfo! +} + +""" +An edge in a connection. +""" +type DepositOrderEdge { + """ + A cursor for use in pagination. + """ + cursor: String! + + """ + The item at the end of the edge. + """ + node: DepositOrder! +} + type FiatBalance implements Node { amountCents: Int! amountCurrency: String! @@ -286,6 +325,27 @@ type Query { last: Int ): BuyCryptoOrderConnection! currentUser: User + depositOrders( + """ + Returns the elements in the list that come after the specified cursor. + """ + after: String + + """ + Returns the elements in the list that come before the specified cursor. + """ + before: String + + """ + Returns the first _n_ elements from the list. + """ + first: Int + + """ + Returns the last _n_ elements from the list. + """ + last: Int + ): DepositOrderConnection! """ Fetches an object given its ID. diff --git a/app/models/deposit_order.rb b/app/models/deposit_order.rb new file mode 100644 index 0000000..947c3c3 --- /dev/null +++ b/app/models/deposit_order.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: deposit_orders +# +# id :bigint not null, primary key +# paid_amount_cents :integer default(0), not null +# received_amount_cents :integer default(0), not null +# status :string not null +# created_at :datetime not null +# updated_at :datetime not null +# user_id :bigint not null +# +# Indexes +# +# index_deposit_orders_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (user_id => users.id) +# +class DepositOrder < ApplicationRecord + include Processable + include Trackable + + belongs_to :user + + monetize :paid_amount_cents + monetize :received_amount_cents +end diff --git a/app/policies/deposit_order_policy.rb b/app/policies/deposit_order_policy.rb new file mode 100644 index 0000000..e6e254c --- /dev/null +++ b/app/policies/deposit_order_policy.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true +class DepositOrderPolicy < ApplicationPolicy + class Scope < Scope + def resolve + return scope.none if user.nil? + + scope.where(user_id: user.id) + end + end +end diff --git a/db/migrate/20210905234913_create_deposit_orders.rb b/db/migrate/20210905234913_create_deposit_orders.rb new file mode 100644 index 0000000..0a31d59 --- /dev/null +++ b/db/migrate/20210905234913_create_deposit_orders.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true +class CreateDepositOrders < ActiveRecord::Migration[6.1] + def change + create_table(:deposit_orders) do |t| + t.references(:user, null: false, foreign_key: true) + t.string(:status, null: false) + + t.integer(:received_amount_cents, null: false, default: 0) + t.integer(:paid_amount_cents, null: false, default: 0) + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 0dccd51..7e98d4f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_08_28_041104) do +ActiveRecord::Schema.define(version: 2021_09_05_234913) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -73,6 +73,16 @@ ActiveRecord::Schema.define(version: 2021_08_28_041104) do t.index ["user_id"], name: "index_buy_crypto_orders_on_user_id" end + create_table "deposit_orders", force: :cascade do |t| + t.bigint "user_id", null: false + t.string "status", null: false + t.integer "received_amount_cents", default: 0, null: false + t.integer "paid_amount_cents", default: 0, null: false + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["user_id"], name: "index_deposit_orders_on_user_id" + end + create_table "fiat_balances", force: :cascade do |t| t.bigint "user_id", null: false t.integer "amount_cents", default: 0, null: false @@ -139,6 +149,7 @@ ActiveRecord::Schema.define(version: 2021_08_28_041104) do add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "balances", "users" add_foreign_key "buy_crypto_orders", "users" + add_foreign_key "deposit_orders", "users" add_foreign_key "fiat_balances", "users" add_foreign_key "sell_crypto_orders", "users" add_foreign_key "stake_orders", "users" diff --git a/erd.svg b/erd.svg index 77ee004..508d039 100644 --- a/erd.svg +++ b/erd.svg @@ -1,83 +1,104 @@ - - - + + XStake - -XStake domain model + +XStake domain model m_AdminUser - -AdminUser - -email -string ∗ U -encrypted_password -string ∗ -remember_created_at -datetime -reset_password_sent_at -datetime -reset_password_token -string + +AdminUser + +email +string ∗ U +encrypted_password +string ∗ +remember_created_at +datetime +reset_password_sent_at +datetime +reset_password_token +string m_Balance - -Balance - -amount -decimal (20,10) ∗ -user_id -integer (8) ∗ FK + +Balance + +amount +decimal (20,10) ∗ +user_id +integer (8) ∗ FK - + m_PaperTrail::Version - -PaperTrail::Version - -event -string ∗ -item_id -integer (8) ∗ FK -item_type -string ∗ -object -text -whodunnit -string + +PaperTrail::Version + +event +string ∗ +item_id +integer (8) ∗ FK +item_type +string ∗ +object +text +whodunnit +string m_Balance->m_PaperTrail::Version - - + + m_BuyCryptoOrder - -BuyCryptoOrder - -paid_amount_cents -integer ∗ -received_amount -decimal (20,10) ∗ -status -string ∗ -user_id -integer (8) ∗ FK + +BuyCryptoOrder + +paid_amount_cents +integer ∗ +received_amount +decimal (20,10) ∗ +status +string ∗ +user_id +integer (8) ∗ FK + + + +m_DepositOrder + +DepositOrder + +paid_amount_cents +integer ∗ +received_amount_cents +integer ∗ +status +string ∗ +user_id +integer (8) ∗ FK + + + +m_DepositOrder->m_PaperTrail::Version + + - + m_FiatBalance FiatBalance @@ -90,13 +111,13 @@ integer (8) ∗ FK - + m_FiatBalance->m_PaperTrail::Version - - + + - + m_SellCryptoOrder SellCryptoOrder @@ -111,7 +132,7 @@ integer (8) ∗ FK - + m_StakeOrder StakeOrder @@ -126,58 +147,64 @@ integer (8) ∗ FK - + m_User - -User - -email -string ∗ U -encrypted_password -string ∗ -first_name -string ∗ -last_name -string ∗ -remember_created_at -datetime -reset_password_sent_at -datetime -reset_password_token -string -wallet_address -string + +User + +email +string ∗ U +encrypted_password +string ∗ +first_name +string ∗ +last_name +string ∗ +remember_created_at +datetime +reset_password_sent_at +datetime +reset_password_token +string +wallet_address +string - + m_User->m_Balance - + - + m_User->m_BuyCryptoOrder - - + + + + + +m_User->m_DepositOrder + + - + m_User->m_FiatBalance - + - + m_User->m_SellCryptoOrder - - + + - + m_User->m_StakeOrder - - + + - + m_UserDocument UserDocument @@ -188,10 +215,10 @@ integer (8) ∗ FK - + m_User->m_UserDocument - - + + diff --git a/spec/factories/deposit_orders.rb b/spec/factories/deposit_orders.rb new file mode 100644 index 0000000..869cf26 --- /dev/null +++ b/spec/factories/deposit_orders.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: deposit_orders +# +# id :bigint not null, primary key +# paid_amount_cents :integer default(0), not null +# received_amount_cents :integer default(0), not null +# status :string not null +# created_at :datetime not null +# updated_at :datetime not null +# user_id :bigint not null +# +# Indexes +# +# index_deposit_orders_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (user_id => users.id) +# +FactoryBot.define do + factory :deposit_order do + user { nil } + status { "MyString" } + end +end diff --git a/spec/models/deposit_order_spec.rb b/spec/models/deposit_order_spec.rb new file mode 100644 index 0000000..13164d1 --- /dev/null +++ b/spec/models/deposit_order_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +# == Schema Information +# +# Table name: deposit_orders +# +# id :bigint not null, primary key +# paid_amount_cents :integer default(0), not null +# received_amount_cents :integer default(0), not null +# status :string not null +# created_at :datetime not null +# updated_at :datetime not null +# user_id :bigint not null +# +# Indexes +# +# index_deposit_orders_on_user_id (user_id) +# +# Foreign Keys +# +# fk_rails_... (user_id => users.id) +# +require "rails_helper" + +RSpec.describe(DepositOrder, type: :model) do + pending "add some examples to (or delete) #{__FILE__}" +end