Skip to content

Commit

Permalink
add routes for ics on customer level
Browse files Browse the repository at this point in the history
  • Loading branch information
annvelents committed Dec 26, 2024
1 parent 7fd7d07 commit 6c851af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/controllers/api/v1/customers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 6c851af

Please sign in to comment.