Skip to content

Commit

Permalink
finish refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
annvelents committed Dec 20, 2024
1 parent 4119b03 commit 9ea2e42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app/services/invoice_custom_sections/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def initialize(invoice_custom_section:, update_params:, selected: false)
def call
invoice_custom_section.update!(update_params)
if selected
SelectService.call(section: invoice_custom_section, organization: invoice_custom_section.organization)
Organizations::SelectInvoiceCustomSectionService.call(section: invoice_custom_section, organization: invoice_custom_section.organization)
else
Deselect::ForOrganizationService.call(section: invoice_custom_section)
Organizations::DeselectInvoiceCustomSectionService.call(section: invoice_custom_section)
end
result.invoice_custom_section = invoice_custom_section
result
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
# frozen_string_literal: true

module Organizations
class DeselectInvoiceCustomSectionService < BaseService
def initialize(section:)
@section = section
@organization = section.organization
super
end
class DeselectInvoiceCustomSectionService < BaseService
def initialize(section:)
@section = section
@organization = section.organization
super
end

def call
deselect_for_organization
result
end
def call
deselect_for_organization
result
end

private
private

attr_reader :section, :organization
attr_reader :section, :organization

def deselect_for_organization
return unless organization.selected_invoice_custom_sections.include?(section)
def deselect_for_organization
return unless organization.selected_invoice_custom_sections.include?(section)

InvoiceCustomSectionSelection.where(
organization_id: organization.id, invoice_custom_section_id: section.id
).destroy_all
result.section = section
end
InvoiceCustomSectionSelection.where(
organization_id: organization.id, invoice_custom_section_id: section.id
).destroy_all
result.section = section
end
end
end

0 comments on commit 9ea2e42

Please sign in to comment.