Skip to content

Commit

Permalink
misc: Remove deprecated group handling
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-pochet committed Jul 8, 2024
1 parent 9e41ac8 commit 45853d9
Show file tree
Hide file tree
Showing 63 changed files with 112 additions and 1,719 deletions.
26 changes: 0 additions & 26 deletions app/controllers/api/v1/billable_metrics/groups_controller.rb

This file was deleted.

15 changes: 4 additions & 11 deletions app/controllers/api/v1/billable_metrics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ class BillableMetricsController < Api::BaseController
def create
service = ::BillableMetrics::CreateService.new
result = service.create(
BillableMetricInput.new(
current_organization,
input_params.merge(organization_id: current_organization.id).to_h.deep_symbolize_keys
).create_input
input_params.merge(organization_id: current_organization.id).to_h.deep_symbolize_keys
)

if result.success?
Expand All @@ -32,10 +29,7 @@ def update

result = ::BillableMetrics::UpdateService.call(
billable_metric:,
params: BillableMetricInput.new(
current_organization,
input_params.to_h.deep_symbolize_keys
).update_input
params: input_params.to_h.deep_symbolize_keys
)

if result.success?
Expand Down Expand Up @@ -84,7 +78,7 @@ def show

def index
metrics = current_organization.billable_metrics
.includes(:filters, :groups)
.includes(:filters)
.order(created_at: :desc)
.page(params[:page])
.per(params[:per_page] || PER_PAGE)
Expand All @@ -110,8 +104,7 @@ def input_params
:weighted_interval,
:recurring,
:field_name,
filters: [:key, {values: []}],
group: {}
filters: [:key, {values: []}]
)
end
end
Expand Down
23 changes: 2 additions & 21 deletions app/controllers/api/v1/plans_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ class PlansController < Api::BaseController
def create
service = ::Plans::CreateService.new
result = service.create(
PlanLegacyInput.new(
current_organization,
input_params
.merge(organization_id: current_organization.id)
.to_h
.deep_symbolize_keys
).create_input
input_params.merge(organization_id: current_organization.id).to_h.deep_symbolize_keys
)

if result.success?
Expand All @@ -24,13 +18,7 @@ def create

def update
plan = current_organization.plans.parents.find_by(code: params[:code])
result = ::Plans::UpdateService.call(
plan:,
params: PlanLegacyInput.new(
current_organization,
input_params.to_h.deep_symbolize_keys
).update_input
)
result = ::Plans::UpdateService.call(plan:, params: input_params.to_h.deep_symbolize_keys)

if result.success?
render_plan(result.plan)
Expand Down Expand Up @@ -119,13 +107,6 @@ def input_params
}
]
},
{
group_properties: [
:group_id,
:invoice_display_name,
{values: {}}
]
},
{tax_codes: []}
]
)
Expand Down
7 changes: 0 additions & 7 deletions app/controllers/api/v1/subscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,6 @@ def plan_overrides
}
]
},
{
group_properties: [
:group_id,
{values: {}},
:invoice_display_name
]
},
{tax_codes: []}
]
}
Expand Down
1 change: 0 additions & 1 deletion app/graphql/types/billable_metrics/create_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class CreateInput < BaseInputObject
argument :weighted_interval, Types::BillableMetrics::WeightedIntervalEnum, required: false

argument :filters, [Types::BillableMetricFilters::Input], required: false
argument :group, GraphQL::Types::JSON, required: false
end
end
end
1 change: 0 additions & 1 deletion app/graphql/types/billable_metrics/update_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class UpdateInput < BaseInputObject
argument :weighted_interval, Types::BillableMetrics::WeightedIntervalEnum, required: false

argument :filters, [Types::BillableMetricFilters::Input], required: false
argument :group, GraphQL::Types::JSON, required: false
end
end
end
13 changes: 0 additions & 13 deletions app/graphql/types/charges/group_properties.rb

This file was deleted.

11 changes: 0 additions & 11 deletions app/graphql/types/charges/group_properties_input.rb

This file was deleted.

19 changes: 0 additions & 19 deletions app/graphql/types/groups/object.rb

This file was deleted.

16 changes: 0 additions & 16 deletions app/graphql/types/groups/usage.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/graphql/types/invoices/invoice_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module InvoiceItem
description 'Invoice Item'

field :id, ID, null: false
field :group, Types::Groups::Object

field :amount_cents, GraphQL::Types::BigInt, null: false
field :amount_currency, Types::CurrencyEnum, null: false
Expand Down
55 changes: 0 additions & 55 deletions app/legacy_inputs/billable_metric_input.rb

This file was deleted.

49 changes: 0 additions & 49 deletions app/legacy_inputs/plan_legacy_input.rb

This file was deleted.

3 changes: 0 additions & 3 deletions app/legacy_inputs/subscription_legacy_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ def create_input
args[:subscription_at] ||= date_in_organization_timezone(args[:subscription_date], end_of_day: false)
end

return args if args[:plan_overrides].blank?

args[:plan_overrides] = PlanLegacyInput.new(organization, args[:plan_overrides]).create_input
args
end
alias_method :update_input, :create_input
Expand Down
34 changes: 0 additions & 34 deletions app/models/billable_metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,40 +59,6 @@ def aggregation_type=(value)
AGGREGATION_TYPES.key?(value&.to_sym) ? super : nil
end

def active_groups
scope = groups
scope = scope.with_discarded if discarded?
scope
end

# NOTE: 1 dimension: all groups, 2 dimensions: all children.
def selectable_groups
groups = active_groups.children.exists? ? active_groups.children : active_groups
groups.includes(:parent).reorder('parent.value', 'groups.value')
end

def active_groups_as_tree
return {} if active_groups.blank?

unless active_groups.children.exists?
return {
key: active_groups.pluck(:key).uniq.first,
values: active_groups.pluck(:value)
}
end

{
key: active_groups.parents.pluck(:key).uniq.first,
values: active_groups.parents.map do |p|
{
name: p.value,
key: p.children.first.key,
values: p.children.pluck(:value)
}
end
}
end

def payable_in_advance?
AGGREGATION_TYPES_PAYABLE_IN_ADVANCE.include?(aggregation_type.to_sym)
end
Expand Down
Loading

0 comments on commit 45853d9

Please sign in to comment.