From 6c851af42a7d64e4b51581f7cd69233564847ea8 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Thu, 26 Dec 2024 05:56:34 +0100 Subject: [PATCH] add routes for ics on customer level --- .../api/v1/customers_controller.rb | 28 +++++++++++++++++++ config/routes.rb | 2 ++ 2 files changed, 30 insertions(+) diff --git a/app/controllers/api/v1/customers_controller.rb b/app/controllers/api/v1/customers_controller.rb index 98a78d41e68d..252352703b59 100644 --- a/app/controllers/api/v1/customers_controller.rb +++ b/app/controllers/api/v1/customers_controller.rb @@ -96,6 +96,34 @@ def checkout_url end end + # note: for DunningCampaign we don't have open api actions at all :thinking: + def update_invoice_custom_sections + customer = current_organization.customers.find_by(external_id: params[:customer_external_id]) + applicable_invoice_custom_section_ids = current_organization.invoice_custom_sections.where(code: params[:invoice_custom_section_codes]).ids + result = ::Customers::UpdateService.call( + customer: customer, + args: params.permit(:skip_invoice_custom_sections).merge(applicable_invoice_custom_section_ids:) + ) + + if result.success? + render_customer(result.customer) + else + render_error_response(result) + end + + def applicable_invoice_custom_sections + customer = current_organization.customers.find_by(external_id: params[:customer_external_id]) + applicable_invoice_custom_sections = customer.applicable_invoice_custom_sections + + render( + json: ::CollectionSerializer.new( + applicable_invoice_custom_sections, + ::V1::InvoiceCustomSectionSerializer, + collection_name: 'applicable_invoice_custom_sections' + ) + ) + end + private def create_params diff --git a/config/routes.rb b/config/routes.rb index 70ee52f264d9..a721655d9b09 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,11 +22,13 @@ resources :customers, param: :external_id, only: %i[create index show destroy] do get :portal_url + get :applicable_invoice_custom_sections get :current_usage, to: 'customers/usage#current' get :past_usage, to: 'customers/usage#past' post :checkout_url + post :update_invoice_custom_sections scope module: :customers do resources :applied_coupons, only: %i[destroy]