Skip to content

Commit

Permalink
feat(netsuite): Cleanup syncs (#2782)
Browse files Browse the repository at this point in the history
## Context

When a users searches for items to map the UI is not displaying all the
items. There is a reason for this
is that the NetSuite SuiteScript limits to 1000 results.

## Description

This PR we change the way we map the items. Instead of selecting the
items from a prefetched list, the user needs to manually fill out the
name, code, and the account id.
  • Loading branch information
ivannovosad authored Nov 6, 2024
1 parent 81f2bf3 commit a24db07
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 432 deletions.
29 changes: 0 additions & 29 deletions app/graphql/mutations/integration_items/fetch_tax_items.rb

This file was deleted.

3 changes: 1 addition & 2 deletions app/graphql/mutations/integrations/netsuite/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class Create < BaseMutation

def resolve(**args)
result = ::Integrations::Netsuite::CreateService
.new(context[:current_user])
.call(**args.merge(organization_id: current_organization.id))
.call(params: args.merge(organization_id: current_organization.id))

result.success? ? result.integration : result_error(result)
end
Expand Down
1 change: 0 additions & 1 deletion app/graphql/types/mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class MutationType < Types::BaseObject

field :fetch_integration_accounts, mutation: Mutations::IntegrationItems::FetchAccounts
field :fetch_integration_items, mutation: Mutations::IntegrationItems::FetchItems
field :fetch_integration_tax_items, mutation: Mutations::IntegrationItems::FetchTaxItems

field :sync_crm_integration_invoice, mutation: Mutations::Integrations::SyncCrmInvoice
field :sync_integration_credit_note, mutation: Mutations::Integrations::SyncCreditNote
Expand Down
17 changes: 0 additions & 17 deletions app/jobs/integrations/aggregator/fetch_tax_items_job.rb

This file was deleted.

11 changes: 4 additions & 7 deletions app/jobs/integrations/aggregator/perform_sync_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ class PerformSyncJob < ApplicationJob
retry_on LagoHttpClient::HttpError, wait: :polynomially_longer, attempts: 3
retry_on RequestLimitError, wait: :polynomially_longer, attempts: 10

def perform(integration:, sync_tax_items: false)
def perform(integration:, sync_items: true)
sync_result = Integrations::Aggregator::SyncService.call(integration:)
sync_result.raise_if_error!

items_result = Integrations::Aggregator::ItemsService.call(integration:)
items_result.raise_if_error!

if sync_tax_items
tax_items_result = Integrations::Aggregator::TaxItemsService.call(integration:)
tax_items_result.raise_if_error!
if sync_items
items_result = Integrations::Aggregator::ItemsService.call(integration:)
items_result.raise_if_error!
end
end
end
Expand Down
7 changes: 1 addition & 6 deletions app/services/integrations/aggregator/sync_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ def sync_list
list = case integration.type
when 'Integrations::NetsuiteIntegration'
{
accounts: 'netsuite-accounts-sync',
items: 'netsuite-items-sync',
subsidiaries: 'netsuite-subsidiaries-sync',
contacts: 'netsuite-contacts-sync',
tax_items: 'netsuite-tax-items-sync'
subsidiaries: 'netsuite-subsidiaries-sync'
}
when 'Integrations::XeroIntegration'
{
Expand All @@ -41,7 +37,6 @@ def sync_list
end

return [list[:items]] if options[:only_items]
return [list[:tax_items]] if options[:only_tax_items]
return [list[:accounts]] if options[:only_accounts]

list.values
Expand Down
69 changes: 0 additions & 69 deletions app/services/integrations/aggregator/tax_items_service.rb

This file was deleted.

43 changes: 24 additions & 19 deletions app/services/integrations/netsuite/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,43 @@
module Integrations
module Netsuite
class CreateService < BaseService
def call(**args)
organization = Organization.find_by(id: args[:organization_id])
attr_reader :params

def initialize(params:)
@params = params

super
end

def call
organization = Organization.find_by(id: params[:organization_id])

unless organization.premium_integrations.include?('netsuite')
return result.not_allowed_failure!(code: 'premium_integration_missing')
end

integration = Integrations::NetsuiteIntegration.new(
organization:,
name: args[:name],
code: args[:code],
client_id: args[:client_id],
client_secret: args[:client_secret],
account_id: args[:account_id],
token_id: args[:token_id],
token_secret: args[:token_secret],
connection_id: args[:connection_id],
script_endpoint_url: args[:script_endpoint_url],
sync_credit_notes: ActiveModel::Type::Boolean.new.cast(args[:sync_credit_notes]),
sync_invoices: ActiveModel::Type::Boolean.new.cast(args[:sync_invoices]),
sync_payments: ActiveModel::Type::Boolean.new.cast(args[:sync_payments]),
sync_sales_orders: ActiveModel::Type::Boolean.new.cast(args[:sync_sales_orders])
name: params[:name],
code: params[:code],
client_id: params[:client_id],
client_secret: params[:client_secret],
account_id: params[:account_id],
token_id: params[:token_id],
token_secret: params[:token_secret],
connection_id: params[:connection_id],
script_endpoint_url: params[:script_endpoint_url],
sync_credit_notes: ActiveModel::Type::Boolean.new.cast(params[:sync_credit_notes]),
sync_invoices: ActiveModel::Type::Boolean.new.cast(params[:sync_invoices]),
sync_payments: ActiveModel::Type::Boolean.new.cast(params[:sync_payments]),
sync_sales_orders: ActiveModel::Type::Boolean.new.cast(params[:sync_sales_orders])
)

integration.save!

if integration.type == 'Integrations::NetsuiteIntegration'
Integrations::Aggregator::SendRestletEndpointJob.perform_later(integration:)
Integrations::Aggregator::PerformSyncJob.set(wait: 2.seconds).perform_later(
integration:,
sync_tax_items: true
)
Integrations::Aggregator::PerformSyncJob.set(wait: 2.seconds).perform_later(integration:, sync_items: false)
end

result.integration = integration
Expand Down
5 changes: 1 addition & 4 deletions app/services/integrations/netsuite/update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ def call

if integration.type == 'Integrations::NetsuiteIntegration' && integration.script_endpoint_url != old_script_url
Integrations::Aggregator::SendRestletEndpointJob.perform_later(integration:)
Integrations::Aggregator::PerformSyncJob.set(wait: 2.seconds).perform_later(
integration:,
sync_tax_items: true
)
Integrations::Aggregator::PerformSyncJob.set(wait: 2.seconds).perform_later(integration:, sync_items: false)
end

result.integration = integration
Expand Down
21 changes: 0 additions & 21 deletions schema.graphql

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

72 changes: 0 additions & 72 deletions schema.json

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

Loading

0 comments on commit a24db07

Please sign in to comment.