From daefa516572d2e2b5b9589f1259b3875d23464d2 Mon Sep 17 00:00:00 2001 From: Jeremy Denquin Date: Mon, 1 Aug 2022 15:38:09 +0200 Subject: [PATCH 1/4] feat: Add Wallet Consumed Amount --- app/graphql/resolvers/wallets_resolver.rb | 2 ++ app/graphql/types/mutation_type.rb | 2 ++ app/graphql/types/wallets/object.rb | 1 + db/schema.rb | 6 ++++-- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/graphql/resolvers/wallets_resolver.rb b/app/graphql/resolvers/wallets_resolver.rb index 419eb3abb6f..06d5b3bd91c 100644 --- a/app/graphql/resolvers/wallets_resolver.rb +++ b/app/graphql/resolvers/wallets_resolver.rb @@ -28,6 +28,8 @@ def resolve(customer_id: nil, ids: nil, page: nil, limit: nil, status: nil) wallets = wallets.where(status: status) if status.present? wallets = wallets.where(id: ids) if ids.present? + wallets.order('status DESC, created_at DESC') + wallets rescue ActiveRecord::RecordNotFound not_found_error diff --git a/app/graphql/types/mutation_type.rb b/app/graphql/types/mutation_type.rb index c1da5d6e43c..7a1a795d08d 100644 --- a/app/graphql/types/mutation_type.rb +++ b/app/graphql/types/mutation_type.rb @@ -45,5 +45,7 @@ class MutationType < Types::BaseObject field :create_customer_wallet, mutation: Mutations::Wallets::Create field :update_customer_wallet, mutation: Mutations::Wallets::Update field :terminate_customer_wallet, mutation: Mutations::Wallets::Terminate + + field :create_customer_wallet_transaction, mutation: Mutations::WalletTransactions::Create end end diff --git a/app/graphql/types/wallets/object.rb b/app/graphql/types/wallets/object.rb index 60369a84014..58798952b8b 100644 --- a/app/graphql/types/wallets/object.rb +++ b/app/graphql/types/wallets/object.rb @@ -14,6 +14,7 @@ class Object < Types::BaseObject field :currency, Types::CurrencyEnum, null: false field :credits_balance, String, null: false field :balance, String, null: false + field :consumed_amount, String, null: false field :consumed_credits, String, null: false field :expiration_date, GraphQL::Types::ISO8601Date, null: true diff --git a/db/schema.rb b/db/schema.rb index db025c0d649..576b19f014d 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[7.0].define(version: 2022_07_28_144707) do +ActiveRecord::Schema[7.0].define(version: 2022_08_01_101144) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -19,10 +19,11 @@ create_table "active_storage_attachments", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false - t.uuid "record_id" + t.uuid "record_id", null: false t.uuid "blob_id", null: false t.datetime "created_at", null: false t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id" + t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true end create_table "active_storage_blobs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| @@ -354,6 +355,7 @@ t.datetime "terminated_at", precision: nil t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.decimal "consumed_amount", precision: 5, default: "0" t.index ["customer_id"], name: "index_wallets_on_customer_id" end From b1c2ad88cc83a43619131c785fd1e40fd7373516 Mon Sep 17 00:00:00 2001 From: Jeremy Denquin Date: Mon, 1 Aug 2022 16:07:30 +0200 Subject: [PATCH 2/4] add file --- .../20220801101144_add_consumed_amount_to_wallets.rb | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 db/migrate/20220801101144_add_consumed_amount_to_wallets.rb diff --git a/db/migrate/20220801101144_add_consumed_amount_to_wallets.rb b/db/migrate/20220801101144_add_consumed_amount_to_wallets.rb new file mode 100644 index 00000000000..1c52383aae9 --- /dev/null +++ b/db/migrate/20220801101144_add_consumed_amount_to_wallets.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class AddConsumedAmountToWallets < ActiveRecord::Migration[7.0] + def change + add_column :wallets, :consumed_amount, :decimal, default: 0, precision: 5 + end +end From a7cd32eda4952a9be0428551bbe8abb3470a3746 Mon Sep 17 00:00:00 2001 From: Jeremy Denquin Date: Mon, 1 Aug 2022 16:10:46 +0200 Subject: [PATCH 3/4] commit schema graphql --- schema.graphql | 25 +++++++++ schema.json | 136 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) diff --git a/schema.graphql b/schema.graphql index c0a4a0a8533..387b7577af1 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1617,6 +1617,19 @@ input CreateCustomerWalletInput { rateAmount: String! } +""" +Autogenerated input type of CreateCustomerWalletTransaction +""" +input CreateCustomerWalletTransactionInput { + """ + A unique identifier for the client performing the mutation. + """ + clientMutationId: String + grantedCredits: String! + paidCredits: String! + walletId: ID! +} + """ Autogenerated input type of CreatePlan """ @@ -2777,6 +2790,16 @@ type Mutation { input: CreateCustomerWalletInput! ): Wallet + """ + Creates a new Customer Wallet Transaction + """ + createCustomerWalletTransaction( + """ + Parameters for CreateCustomerWalletTransaction + """ + input: CreateCustomerWalletTransactionInput! + ): WalletTransaction + """ Creates a new Plan """ @@ -3562,6 +3585,7 @@ type User { type Wallet { balance: String! + consumedAmount: String! consumedCredits: String! createdAt: ISO8601DateTime! creditsBalance: String! @@ -3585,6 +3609,7 @@ type WalletCollection { type WalletDetails { balance: String! + consumedAmount: String! consumedCredits: String! createdAt: ISO8601DateTime! creditsBalance: String! diff --git a/schema.json b/schema.json index 95ba81b92bd..a9975d341a6 100644 --- a/schema.json +++ b/schema.json @@ -4773,6 +4773,77 @@ ], "enumValues": null }, + { + "kind": "INPUT_OBJECT", + "name": "CreateCustomerWalletTransactionInput", + "description": "Autogenerated input type of CreateCustomerWalletTransaction", + "interfaces": null, + "possibleTypes": null, + "fields": null, + "inputFields": [ + { + "name": "clientMutationId", + "description": "A unique identifier for the client performing the mutation.", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "walletId", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "paidCredits", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "grantedCredits", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + } + ], + "enumValues": null + }, { "kind": "INPUT_OBJECT", "name": "CreatePlanInput", @@ -8927,6 +8998,35 @@ } ] }, + { + "name": "createCustomerWalletTransaction", + "description": "Creates a new Customer Wallet Transaction", + "type": { + "kind": "OBJECT", + "name": "WalletTransaction", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null, + "args": [ + { + "name": "input", + "description": "Parameters for CreateCustomerWalletTransaction", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "INPUT_OBJECT", + "name": "CreateCustomerWalletTransactionInput", + "ofType": null + } + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + } + ] + }, { "name": "createPlan", "description": "Creates a new Plan", @@ -13362,6 +13462,24 @@ ] }, + { + "name": "consumedAmount", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null, + "args": [ + + ] + }, { "name": "consumedCredits", "description": null, @@ -13682,6 +13800,24 @@ ] }, + { + "name": "consumedAmount", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null, + "args": [ + + ] + }, { "name": "consumedCredits", "description": null, From a620ab6046aa6989abad873ce737dec8c3f9b938 Mon Sep 17 00:00:00 2001 From: Alexandre Monjol Date: Mon, 1 Aug 2022 18:05:31 +0200 Subject: [PATCH 4/4] Fix returned wallet order --- app/graphql/resolvers/wallets_resolver.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/graphql/resolvers/wallets_resolver.rb b/app/graphql/resolvers/wallets_resolver.rb index 06d5b3bd91c..d0f9f7aa00e 100644 --- a/app/graphql/resolvers/wallets_resolver.rb +++ b/app/graphql/resolvers/wallets_resolver.rb @@ -28,9 +28,7 @@ def resolve(customer_id: nil, ids: nil, page: nil, limit: nil, status: nil) wallets = wallets.where(status: status) if status.present? wallets = wallets.where(id: ids) if ids.present? - wallets.order('status DESC, created_at DESC') - - wallets + wallets.order(status: :asc, created_at: :desc) rescue ActiveRecord::RecordNotFound not_found_error end