Class: Assistant::TechnicalArticleManagementToolBuilder::UpdateTool

Inherits:
ManagementTool
  • Object
show all
Defined in:
app/services/assistant/technical_article_management_tool_builder.rb

Overview

Updates only a current draft using an optimistic edit token.

Instance Method Summary collapse

Methods inherited from ManagementTool

#initialize

Constructor Details

This class inherits a constructor from Assistant::TechnicalArticleManagementToolBuilder::ManagementTool

Instance Method Details

#execute(id:, edit_token:, **attributes) ⇒ String

Returns JSON update result.

Parameters:

  • id (Integer)

    Technical Article ID

  • edit_token (String)

    current optimistic token

  • attributes (Hash)

    partial draft changes

Options Hash (**attributes):

  • :subject (String)

    article title

  • :description (String, nil)

    article scope or summary HTML

  • :solution (String)

    troubleshooting HTML

  • :problem_code (String, nil)

    related support problem code

  • :warranty_parts (Boolean)

    whether parts are covered

  • :warranty_labor (Boolean)

    whether labor is covered

  • :serial_number_low_range (Integer, nil)

    lower applicable serial number

  • :serial_number_high_range (Integer, nil)

    upper applicable serial number

  • :time_required (Integer, nil)

    expected completion time

  • :product_line_ids (Array<Integer>)

    applicable Product Line IDs

  • :product_category_ids (Array<Integer>)

    applicable Product Category IDs

  • :item_ids (Array<Integer>)

    applicable Item IDs

  • :tags (Array<String>)

    search and editorial tags

  • :user_id (Integer, nil)

    review assignee Employee ID

Returns:

  • (String)

    JSON update result



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'app/services/assistant/technical_article_management_tool_builder.rb', line 363

def execute(id:, edit_token:, **attributes)
  safely('update') do
    attrs = attributes.symbolize_keys.slice(*EDITABLE_FIELDS)
    raise ToolError, 'No editable fields were provided.' if attrs.empty?

    TechnicalArticleManagementToolBuilder.validate_association_ids!(attrs)
    with_current_draft(id, edit_token) do |article|
      article.assign_attributes(attrs)
      article.updater_id = require_actor!.id
      article.save!
      article.touch unless article.previous_changes.key?('updated_at')
      return response(article)
    end
  end
end

#nameString

Returns stable tool name.

Returns:

  • (String)

    stable tool name



343
# File 'app/services/assistant/technical_article_management_tool_builder.rb', line 343

def name = 'update_technical_article_draft'