Class: ZendeskController

Inherits:
ApplicationController show all
Includes:
AttachmentsHelper
Defined in:
app/controllers/zendesk_controller.rb

Instance Method Summary collapse

Methods included from AttachmentsHelper

#base64_attachments_to_files, #base64_with_filename_to_files

Methods included from AuthentificationHelper

#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token

Instance Method Details

#create_commentObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/zendesk_controller.rb', line 40

def create_comment
  ticket_id = params[:ticket_id]
  comment = params[:comment]
  base_64_attachments = params[:base64_attachments] || []

  attachments = base64_attachments_to_files(base_64_attachments)

  data = ZendeskApiService.new(company: current_company).create_ticket_comment(
    ticket_id: ticket_id,
    local_user: current_user,
    html: comment,
    uploads: attachments
  )

  render json: {
    data: data
  }
end

#create_ticketObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/zendesk_controller.rb', line 15

def create_ticket
  subject = params[:subject]
  description = params[:description]
  base_64_attachments = params[:base64_attachments] || []
  company = if current_user.system_record
              Company.find_by(company_id: params[:company_id]) || current_company
            else
              current_company
            end

  attachments = base64_attachments_to_files(base_64_attachments)

  data = ZendeskApiService.new(company: company).create_ticket(
    local_user: current_user,
    subject: subject,
    description: description,
    uploads: attachments,
    priority: params[:priority] || 'normal'
  )

  render json: {
    redirect_to: "/app/tickets/#{data['id']}"
  }
end

#ticketObject



78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/zendesk_controller.rb', line 78

def ticket
  ticket_id = params[:ticket_id]

  data = ZendeskApiService.new(company: current_company).ticket_with_requester(
    ticket_id
  )

  render json: {
    data: data
  }
end

#ticketsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/zendesk_controller.rb', line 59

def tickets
  page = params[:page]&.to_i
  per_page = params[:per_page]&.to_i
  sort_by = params[:sort_by] || 'updated_at'
  sort_order = params[:sort_order] || 'desc'

  data,  = ZendeskApiService.new(company: current_company).populated_tickets(
    page: page,
    per_page: per_page,
    sort_by: sort_by,
    sort_order: sort_order
  ).values_at(:data, :metadata)

  render json: {
    data: data,
    metadata: 
  }
end

#update_organization_suspendedObject



7
8
9
10
11
12
13
# File 'app/controllers/zendesk_controller.rb', line 7

def update_organization_suspended
  ZendeskApiService.new(
    company: current_company
  ).suspend_organization

  render json: {}
end