Class: RestaurantCpt::Operations::SettingByOwner

Inherits:
Trailblazer::Operation
  • Object
show all
Defined in:
app/concepts/restaurant_cpt/operations/settings_by_owner.rb

Instance Method Summary collapse

Instance Method Details

#clean_inventory_source_params!(options) ⇒ Object



38
39
40
41
42
# File 'app/concepts/restaurant_cpt/operations/settings_by_owner.rb', line 38

def clean_inventory_source_params!(options, *)
  options['params'].delete('inventory_source') if options['params']['inventory_source'].present?

  true
end

#clean_phone_params!(options) ⇒ Object



30
31
32
33
34
35
36
# File 'app/concepts/restaurant_cpt/operations/settings_by_owner.rb', line 30

def clean_phone_params!(options, *)
  options['params']['phone'].delete!("^\u{0000}-\u{007F}") if options['params']['phone'].present?
  if options['params']['owner_attributes'].present? && options['params']['owner_attributes']['phone'].present?
    options['params']['owner_attributes']['phone'].delete!("^\u{0000}-\u{007F}")
  end
  true
end

#convert_to_date!(options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/concepts/restaurant_cpt/operations/settings_by_owner.rb', line 16

def convert_to_date!(options, *)
  %w[expiry_date start_date].each do |param|
    next if options['params'][param].blank?

    options['params'][param] = begin
      Date.parse(options['params'][param])
    rescue StandardError
      options['model'].errors.add(param.to_sym, 'Invalid date')
      return false
    end
  end
  true
end

#persist!(options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/concepts/restaurant_cpt/operations/settings_by_owner.rb', line 44

def persist!(options, *)
  success = false
  ActiveRecord::Base.transaction do
    options['model'].assign_attributes(options['params'])
    if options['model'].valid?
      options['model'].save!
      Restaurants::ClearUiCacheWorker.perform_async(options['model'].id, true, true)
      success = true
    else
      options['error_message'] = options['model'].errors.full_messages
      success = false
    end
  end
  success
end