Class: RestaurantCpt::Operations::SettingByOwner
- Inherits:
-
Trailblazer::Operation
- Object
- Trailblazer::Operation
- RestaurantCpt::Operations::SettingByOwner
- Defined in:
- app/concepts/restaurant_cpt/operations/settings_by_owner.rb
Instance Method Summary collapse
- #clean_inventory_source_params!(options) ⇒ Object
- #clean_phone_params!(options) ⇒ Object
- #convert_to_date!(options) ⇒ Object
- #persist!(options) ⇒ Object
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!(, *) ['params'].delete('inventory_source') if ['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!(, *) ['params']['phone'].delete!("^\u{0000}-\u{007F}") if ['params']['phone'].present? if ['params']['owner_attributes'].present? && ['params']['owner_attributes']['phone'].present? ['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!(, *) %w[expiry_date start_date].each do |param| next if ['params'][param].blank? ['params'][param] = begin Date.parse(['params'][param]) rescue StandardError ['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!(, *) success = false ActiveRecord::Base.transaction do ['model'].assign_attributes(['params']) if ['model'].valid? ['model'].save! Restaurants::ClearUiCacheWorker.perform_async(['model'].id, true, true) success = true else ['error_message'] = ['model'].errors. success = false end end success end |