Skip to content

Commit

Permalink
feat(cascade-plan-changes): add api and GQL support for cascade featu…
Browse files Browse the repository at this point in the history
…re (#2726)

## Context

Currently when plan is updated, these changes are not cascaded to all
the children plans.

## Description

This PR adds `cascade_updates` attribute that allows user to skip
cascade action.

Also, this PR includes `has_overridden_plans` attribute on GQL plan
object.
  • Loading branch information
lovrocolic authored Oct 31, 2024
1 parent 90accd3 commit 8220622
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/v1/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def input_params
:trial_period,
:pay_in_advance,
:bill_charges_monthly,
:cascade_updates,
tax_codes: [],
minimum_commitment: [
:id,
Expand Down
1 change: 1 addition & 0 deletions app/graphql/mutations/plans/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Update < BaseMutation
argument :amount_cents, GraphQL::Types::BigInt, required: true
argument :amount_currency, Types::CurrencyEnum, required: true
argument :bill_charges_monthly, Boolean, required: false
argument :cascade_updates, Boolean, required: false
argument :code, String, required: true
argument :description, String, required: false
argument :id, String, required: true
Expand Down
6 changes: 6 additions & 0 deletions app/graphql/types/plans/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Object < Types::BaseObject
field :charges, [Types::Charges::Object]
field :taxes, [Types::Taxes::Object]

field :has_overridden_plans, Boolean

field :created_at, GraphQL::Types::ISO8601DateTime, null: false
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false

Expand All @@ -46,6 +48,10 @@ def charges_count
object.charges.count
end

def has_overridden_plans
object.children.any?
end

def subscriptions_count
count = object.subscriptions.count
return count unless object.children
Expand Down
2 changes: 2 additions & 0 deletions schema.graphql

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

26 changes: 26 additions & 0 deletions schema.json

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

1 change: 1 addition & 0 deletions spec/graphql/types/plans/object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
it { is_expected.to have_field(:bill_charges_monthly).of_type('Boolean') }
it { is_expected.to have_field(:code).of_type('String!') }
it { is_expected.to have_field(:description).of_type('String') }
it { is_expected.to have_field(:has_overridden_plans).of_type('Boolean') }
it { is_expected.to have_field(:interval).of_type('PlanInterval!') }
it { is_expected.to have_field(:invoice_display_name).of_type('String') }
it { is_expected.to have_field(:minimum_commitment).of_type('Commitment') }
Expand Down

0 comments on commit 8220622

Please sign in to comment.