add.rb 937 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class User::Current::TaskbarItem::Add < BaseMutation
  4. description 'Create a taskbar item for the currently logged-in user.'
  5. argument :input, Gql::Types::Input::User::TaskbarItemInputType, required: true, description: 'The taskbar item parameters.'
  6. field :taskbar_item, Gql::Types::User::TaskbarItemType, description: 'The created taskbar item.'
  7. def resolve(input:)
  8. hash = input.to_h.merge(
  9. user_id: context.current_user.id,
  10. active: false,
  11. preferences: { dirty: input[:dirty].presence || false }
  12. )
  13. begin
  14. taskbar_item = Taskbar.create!(hash)
  15. rescue ActiveRecord::RecordInvalid
  16. # noop
  17. end
  18. taskbar_item ||= Taskbar.where(user: context.current_user, app: input[:app], key: input[:key]).first
  19. { taskbar_item: }
  20. end
  21. end
  22. end