diff --git a/app/graphql/mutations/customers/update_invoice_grace_period.rb b/app/graphql/mutations/customers/update_invoice_grace_period.rb index 23dee615c310..14e097d0141b 100644 --- a/app/graphql/mutations/customers/update_invoice_grace_period.rb +++ b/app/graphql/mutations/customers/update_invoice_grace_period.rb @@ -11,7 +11,7 @@ class UpdateInvoiceGracePeriod < BaseMutation argument :id, ID, required: true argument :invoice_grace_period, Integer, required: false - type Types::Customers::SingleObject + type Types::Customers::Object def resolve(id:, invoice_grace_period:) result = ::Customers::UpdateService.new(context[:current_user]).update(id:, invoice_grace_period:) diff --git a/app/graphql/mutations/customers/update_vat_rate.rb b/app/graphql/mutations/customers/update_vat_rate.rb index b613b0d8a858..7b0e38a239ff 100644 --- a/app/graphql/mutations/customers/update_vat_rate.rb +++ b/app/graphql/mutations/customers/update_vat_rate.rb @@ -11,7 +11,7 @@ class UpdateVatRate < BaseMutation argument :id, ID, required: true argument :vat_rate, Float, required: false - type Types::Customers::SingleObject + type Types::Customers::Object def resolve(id:, vat_rate:) result = ::Customers::UpdateService.new(context[:current_user]).update( diff --git a/app/graphql/resolvers/customer_resolver.rb b/app/graphql/resolvers/customer_resolver.rb index 13640672fddc..197626e618f1 100644 --- a/app/graphql/resolvers/customer_resolver.rb +++ b/app/graphql/resolvers/customer_resolver.rb @@ -9,7 +9,7 @@ class CustomerResolver < Resolvers::BaseResolver argument :id, ID, required: true, description: 'Uniq ID of the customer' - type Types::Customers::SingleObject, null: true + type Types::Customers::Object, null: true def resolve(id: nil) validate_organization! diff --git a/app/graphql/types/customers/object.rb b/app/graphql/types/customers/object.rb index 6f07acd09bd3..0a9cec503c4a 100644 --- a/app/graphql/types/customers/object.rb +++ b/app/graphql/types/customers/object.rb @@ -36,7 +36,14 @@ class Object < Types::BaseObject field :billing_configuration, Types::Customers::BillingConfiguration, null: true field :provider_customer, Types::PaymentProviderCustomers::Provider, null: true - field :subscriptions, [Types::Subscriptions::Object] + field :subscriptions, [Types::Subscriptions::Object], resolver: Resolvers::Customers::SubscriptionsResolver + + field :invoices, [Types::Invoices::Object] + + field :applied_add_ons, [Types::AppliedAddOns::Object], null: true + field :applied_coupons, [Types::AppliedCoupons::Object], null: true + + field :credit_notes, [Types::CreditNotes::Object], null: true field :created_at, GraphQL::Types::ISO8601DateTime, null: false field :updated_at, GraphQL::Types::ISO8601DateTime, null: false @@ -58,6 +65,18 @@ class Object < Types::BaseObject description 'Check if customer attributes are editable' end + def invoices + object.invoices.order(created_at: :desc) + end + + def applied_coupons + object.applied_coupons.active.order(created_at: :asc) + end + + def applied_add_ons + object.applied_add_ons.order(created_at: :desc) + end + def has_active_wallet object.wallets.active.any? end diff --git a/app/graphql/types/customers/single_object.rb b/app/graphql/types/customers/single_object.rb deleted file mode 100644 index 0bad6a3c91d7..000000000000 --- a/app/graphql/types/customers/single_object.rb +++ /dev/null @@ -1,28 +0,0 @@ -# frozen_string_literal: true - -module Types - module Customers - class SingleObject < Types::Customers::Object - graphql_name 'CustomerDetails' - - field :invoices, [Types::Invoices::Object] - field :subscriptions, [Types::Subscriptions::Object], resolver: Resolvers::Customers::SubscriptionsResolver - field :applied_coupons, [Types::AppliedCoupons::Object], null: true - field :applied_add_ons, [Types::AppliedAddOns::Object], null: true - field :credit_notes, [Types::CreditNotes::Object], null: true - field :currency, Types::CurrencyEnum, null: true - - def invoices - object.invoices.order(created_at: :desc) - end - - def applied_coupons - object.applied_coupons.active.order(created_at: :asc) - end - - def applied_add_ons - object.applied_add_ons.order(created_at: :desc) - end - end - end -end diff --git a/schema.graphql b/schema.graphql index 2187dbfbd01a..e0d3b06a25dd 100644 --- a/schema.graphql +++ b/schema.graphql @@ -2458,82 +2458,6 @@ type CurrentVersion { } type Customer { - """ - Number of active subscriptions per customer - """ - activeSubscriptionCount: Int! - addressLine1: String - addressLine2: String - applicableTimezone: TimezoneEnum! - billingConfiguration: CustomerBillingConfiguration - - """ - Check if customer attributes are editable - """ - canEditAttributes: Boolean! - city: String - country: CountryCode - createdAt: ISO8601DateTime! - - """ - Credit notes credits balance available per customer - """ - creditNotesBalanceAmountCents: BigInt! - - """ - Number of available credits from credit notes per customer - """ - creditNotesCreditsAvailableCount: Int! - currency: CurrencyEnum - deletedAt: ISO8601DateTime - email: String - externalId: String! - - """ - Define if a customer has an active wallet - """ - hasActiveWallet: Boolean! - - """ - Define if a customer has any credit note - """ - hasCreditNotes: Boolean! - id: ID! - invoiceGracePeriod: Int - legalName: String - legalNumber: String - logoUrl: String - metadata: [CustomerMetadata!] - name: String - paymentProvider: ProviderTypeEnum - phone: String - providerCustomer: ProviderCustomer - sequentialId: String! - slug: String! - state: String - subscriptions: [Subscription!] - timezone: TimezoneEnum - updatedAt: ISO8601DateTime! - url: String - vatRate: Float - zipcode: String -} - -type CustomerBillingConfiguration { - documentLocale: String - id: ID! -} - -input CustomerBillingConfigurationInput { - documentLocale: String -} - -type CustomerCollection { - collection: [Customer!]! - metadata: CollectionMetadata! -} - -type CustomerDetails { """ Number of active subscriptions per customer """ @@ -2608,6 +2532,20 @@ type CustomerDetails { zipcode: String } +type CustomerBillingConfiguration { + documentLocale: String + id: ID! +} + +input CustomerBillingConfigurationInput { + documentLocale: String +} + +type CustomerCollection { + collection: [Customer!]! + metadata: CollectionMetadata! +} + type CustomerMetadata { createdAt: ISO8601DateTime! displayInInvoice: Boolean! @@ -3500,7 +3438,7 @@ type Mutation { Parameters for UpdateCustomerInvoiceGracePeriod """ input: UpdateCustomerInvoiceGracePeriodInput! - ): CustomerDetails + ): Customer """ Assign the vat rate to Customers @@ -3510,7 +3448,7 @@ type Mutation { Parameters for UpdateCustomerVatRate """ input: UpdateCustomerVatRateInput! - ): CustomerDetails + ): Customer """ Updates a new Customer Wallet @@ -3792,7 +3730,7 @@ type Query { Uniq ID of the customer """ id: ID! - ): CustomerDetails + ): Customer """ Query customer's credit note diff --git a/schema.json b/schema.json index 60825b21ff9a..a2c320604f95 100644 --- a/schema.json +++ b/schema.json @@ -6911,716 +6911,6 @@ "description": null, "interfaces": [ - ], - "possibleTypes": null, - "fields": [ - { - "name": "activeSubscriptionCount", - "description": "Number of active subscriptions per customer", - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "Int", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "addressLine1", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "addressLine2", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "applicableTimezone", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "ENUM", - "name": "TimezoneEnum", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "billingConfiguration", - "description": null, - "type": { - "kind": "OBJECT", - "name": "CustomerBillingConfiguration", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "canEditAttributes", - "description": "Check if customer attributes are editable", - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "Boolean", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "city", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "country", - "description": null, - "type": { - "kind": "ENUM", - "name": "CountryCode", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "createdAt", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "ISO8601DateTime", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "creditNotesBalanceAmountCents", - "description": "Credit notes credits balance available per customer", - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "BigInt", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "creditNotesCreditsAvailableCount", - "description": "Number of available credits from credit notes per customer", - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "Int", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "currency", - "description": null, - "type": { - "kind": "ENUM", - "name": "CurrencyEnum", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "deletedAt", - "description": null, - "type": { - "kind": "SCALAR", - "name": "ISO8601DateTime", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "email", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "externalId", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "hasActiveWallet", - "description": "Define if a customer has an active wallet", - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "Boolean", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "hasCreditNotes", - "description": "Define if a customer has any credit note", - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "Boolean", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "id", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "ID", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "invoiceGracePeriod", - "description": null, - "type": { - "kind": "SCALAR", - "name": "Int", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "legalName", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "legalNumber", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "logoUrl", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "metadata", - "description": null, - "type": { - "kind": "LIST", - "name": null, - "ofType": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "OBJECT", - "name": "CustomerMetadata", - "ofType": null - } - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "name", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "paymentProvider", - "description": null, - "type": { - "kind": "ENUM", - "name": "ProviderTypeEnum", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "phone", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "providerCustomer", - "description": null, - "type": { - "kind": "OBJECT", - "name": "ProviderCustomer", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "sequentialId", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "slug", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "state", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "subscriptions", - "description": null, - "type": { - "kind": "LIST", - "name": null, - "ofType": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "OBJECT", - "name": "Subscription", - "ofType": null - } - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "timezone", - "description": null, - "type": { - "kind": "ENUM", - "name": "TimezoneEnum", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "updatedAt", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "ISO8601DateTime", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "url", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "vatRate", - "description": null, - "type": { - "kind": "SCALAR", - "name": "Float", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "zipcode", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - } - ], - "inputFields": null, - "enumValues": null - }, - { - "kind": "OBJECT", - "name": "CustomerBillingConfiguration", - "description": null, - "interfaces": [ - - ], - "possibleTypes": null, - "fields": [ - { - "name": "documentLocale", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "id", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "ID", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - } - ], - "inputFields": null, - "enumValues": null - }, - { - "kind": "INPUT_OBJECT", - "name": "CustomerBillingConfigurationInput", - "description": null, - "interfaces": null, - "possibleTypes": null, - "fields": null, - "inputFields": [ - { - "name": "documentLocale", - "description": null, - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - }, - "defaultValue": null, - "isDeprecated": false, - "deprecationReason": null - } - ], - "enumValues": null - }, - { - "kind": "OBJECT", - "name": "CustomerCollection", - "description": null, - "interfaces": [ - - ], - "possibleTypes": null, - "fields": [ - { - "name": "collection", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "LIST", - "name": null, - "ofType": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "OBJECT", - "name": "Customer", - "ofType": null - } - } - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - }, - { - "name": "metadata", - "description": null, - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "OBJECT", - "name": "CollectionMetadata", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null, - "args": [ - - ] - } - ], - "inputFields": null, - "enumValues": null - }, - { - "kind": "OBJECT", - "name": "CustomerDetails", - "description": null, - "interfaces": [ - ], "possibleTypes": null, "fields": [ @@ -8311,6 +7601,131 @@ "inputFields": null, "enumValues": null }, + { + "kind": "OBJECT", + "name": "CustomerBillingConfiguration", + "description": null, + "interfaces": [ + + ], + "possibleTypes": null, + "fields": [ + { + "name": "documentLocale", + "description": null, + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null, + "args": [ + + ] + }, + { + "name": "id", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "ID", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null, + "args": [ + + ] + } + ], + "inputFields": null, + "enumValues": null + }, + { + "kind": "INPUT_OBJECT", + "name": "CustomerBillingConfigurationInput", + "description": null, + "interfaces": null, + "possibleTypes": null, + "fields": null, + "inputFields": [ + { + "name": "documentLocale", + "description": null, + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + }, + "defaultValue": null, + "isDeprecated": false, + "deprecationReason": null + } + ], + "enumValues": null + }, + { + "kind": "OBJECT", + "name": "CustomerCollection", + "description": null, + "interfaces": [ + + ], + "possibleTypes": null, + "fields": [ + { + "name": "collection", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "Customer", + "ofType": null + } + } + } + }, + "isDeprecated": false, + "deprecationReason": null, + "args": [ + + ] + }, + { + "name": "metadata", + "description": null, + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "OBJECT", + "name": "CollectionMetadata", + "ofType": null + } + }, + "isDeprecated": false, + "deprecationReason": null, + "args": [ + + ] + } + ], + "inputFields": null, + "enumValues": null + }, { "kind": "OBJECT", "name": "CustomerMetadata", @@ -13563,7 +12978,7 @@ "description": "Assign the invoice grace period to Customers", "type": { "kind": "OBJECT", - "name": "CustomerDetails", + "name": "Customer", "ofType": null }, "isDeprecated": false, @@ -13592,7 +13007,7 @@ "description": "Assign the vat rate to Customers", "type": { "kind": "OBJECT", - "name": "CustomerDetails", + "name": "Customer", "ofType": null }, "isDeprecated": false, @@ -15508,7 +14923,7 @@ "description": "Query a single customer of an organization", "type": { "kind": "OBJECT", - "name": "CustomerDetails", + "name": "Customer", "ofType": null }, "isDeprecated": false,