update_order.rb 611 B

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::User::Overview::UpdateOrder < Service::Base
  3. attr_reader :user, :overviews
  4. def initialize(user, overviews)
  5. super()
  6. @user = user
  7. @overviews = overviews
  8. end
  9. def execute
  10. ActiveRecord::Base.transaction do
  11. reset_existing
  12. create_new
  13. end
  14. end
  15. private
  16. def reset_existing
  17. ::User::OverviewSorting
  18. .where(user:)
  19. .destroy_all
  20. end
  21. def create_new
  22. overviews.each do |overview|
  23. overview
  24. .overview_sortings
  25. .create! user:
  26. end
  27. end
  28. end