add.rb 951 B

1234567891011121314151617181920212223242526272829303132
  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. {
  20. taskbar_item:
  21. }
  22. end
  23. end
  24. end