create.rb 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class Ticket::Create < BaseMutation
  4. include Gql::Mutations::Ticket::Concerns::HandlesGroup
  5. description 'Create a new ticket.'
  6. argument :input, Gql::Types::Input::Ticket::CreateInputType, description: 'The ticket data'
  7. field :ticket, Gql::Types::TicketType, description: 'The created ticket. If this is present but empty, the mutation was successful but the user has no rights to view the new ticket.'
  8. def self.authorize(_obj, ctx)
  9. ctx.current_user.permissions?(['ticket.agent', 'ticket.customer'])
  10. end
  11. def resolve(input:)
  12. return group_has_no_email_error if !group_has_email?(input: input)
  13. {
  14. ticket: Service::Ticket::Create
  15. .new(current_user: context.current_user)
  16. .execute(ticket_data: input)
  17. }
  18. rescue Exceptions::InvalidAttribute => e
  19. field = e.attribute == 'email_recipient' ? 'customer_id' : e.attribute
  20. error_response({ field:, message: e.message })
  21. end
  22. end
  23. end