Skip to content

Commit

Permalink
misc(Customer): merge single object and object types
Browse files Browse the repository at this point in the history
  • Loading branch information
ansmonjol committed Mar 13, 2023
1 parent 5d8007d commit a042939
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 824 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:)
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/mutations/customers/update_vat_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/resolvers/customer_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
21 changes: 20 additions & 1 deletion app/graphql/types/customers/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 0 additions & 28 deletions app/graphql/types/customers/single_object.rb

This file was deleted.

96 changes: 17 additions & 79 deletions schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a042939

Please sign in to comment.