item_upsert.rb 1.2 KB

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class Ticket::Checklist::ItemUpsert < BaseMutation
  4. description 'Update or create a ticket checklist item.'
  5. argument :checklist_id, GraphQL::Types::ID, required: true, loads: Gql::Types::ChecklistType, description: 'ID of the ticket checklist to update or create an item for.'
  6. argument :checklist_item_id, GraphQL::Types::ID, required: false, loads: Gql::Types::Checklist::ItemType, description: 'ID of the ticket checklist item to update.'
  7. argument :input, Gql::Types::Input::Ticket::Checklist::ItemInputType, required: true, description: 'Input field values of the ticket checklist item.'
  8. field :checklist_item, Gql::Types::Checklist::ItemType, null: true, description: 'Updated or created checklist item.'
  9. def resolve(checklist:, input:, checklist_item: nil)
  10. if checklist_item
  11. checklist_item.update!(**input)
  12. else
  13. checklist_item = checklist.items.create!(input.to_h)
  14. end
  15. {
  16. checklist_item:
  17. }
  18. end
  19. def authorized?(checklist:, input:, checklist_item: nil)
  20. Pundit.authorize(context.current_user, checklist.ticket, :update?)
  21. end
  22. end
  23. end