Class: RestaurantTagCpt::Operations::Update
- Inherits:
-
Trailblazer::Operation
- Object
- Trailblazer::Operation
- RestaurantTagCpt::Operations::Update
- Defined in:
- app/concepts/restaurant_tag_cpt/operations/update.rb
Instance Method Summary collapse
- #find_model!(options) ⇒ Object
- #map_attributes!(options) ⇒ Object
- #update_restaurants!(options) ⇒ Object
Instance Method Details
#find_model!(options) ⇒ Object
13 14 15 |
# File 'app/concepts/restaurant_tag_cpt/operations/update.rb', line 13 def find_model!(, *) ['model'] = ::RestaurantTagCpt::ModelDecorator.find_by(id: [:id]) end |
#map_attributes!(options) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/concepts/restaurant_tag_cpt/operations/update.rb', line 17 def map_attributes!(, *) MyLocaleManager.available_locales.each do |locale| tag_value = [::OpCons::CONTRACT_DEFAULT].send("tag_#{locale}").to_s.strip # Only update if tag_value is present # Don't set to nil for required locales (en, th, cn) to avoid validation errors if tag_value.present? title = "#{[::OpCons::CONTRACT_DEFAULT].category}:#{tag_value}" [::OpCons::MODEL].send(:"title_#{locale}=", title) elsif !RestaurantTag::REQUIRED_LOCALES.include?(locale) # For optional locales, allow setting to nil [::OpCons::MODEL].send(:"title_#{locale}=", nil) end # For required locales (en, th, cn), preserve existing value if tag_value is blank end end |
#update_restaurants!(options) ⇒ Object
34 35 36 37 |
# File 'app/concepts/restaurant_tag_cpt/operations/update.rb', line 34 def update_restaurants!(, *) Restaurant.joins(:primary_tags).where(primary_tags: { restaurant_tag_id: ['result.contract.default'].model.id }). update_all(updated_at: Time.zone.now) end |