Class: LesliSupport::TicketsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/lesli_support/tickets_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



62
63
64
65
66
67
68
69
70
# File 'app/controllers/lesli_support/tickets_controller.rb', line 62

def create
    ticket = TicketService.new(current_user, query).create(ticket_params)

    if ticket.successful?
        respond_with_successful(ticket.result)
    else 
        respond_with_error(ticket.errors)
    end
end

#destroyObject



99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/controllers/lesli_support/tickets_controller.rb', line 99

def destroy
    return respond_with_not_found unless @ticket
    return respond_with_unauthorized unless @ticket.is_editable_by?(current_user)

    ticket_destroy_response = TicketServices.destroy(current_user, @ticket)

    if ticket_destroy_response.successful?
        respond_with_successful
    else
        respond_with_error(ticket_destroy_response.payload.errors.full_messages.to_sentence)
    end
end

#editObject



59
60
# File 'app/controllers/lesli_support/tickets_controller.rb', line 59

def edit
end

#imagesObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/controllers/lesli_support/tickets_controller.rb', line 112

def images
    return respond_with_not_found unless @ticket

    images = @ticket.files.filter do |file|
        file_name = ""
        file_name = file.attachment_s3_identifier.downcase if file.attachment_s3_identifier
        file_name = file.attachment_identifier.downcase if file.attachment_identifier

        file_name.end_with?('png') || file_name.end_with?('jpg') || file_name.end_with?('jpeg')
    end

    images = images.map do |image|
        {
            id: image.id,
            name: image.name,
            src: "/help/tickets/#{@ticket.id}/files/#{image.id}",
            href: "/help/tickets/#{@ticket.id}/files/#{image.id}?view=true"
        }
    end

    respond_with_successful(images)
end

#indexObject



37
38
39
40
41
42
43
44
45
# File 'app/controllers/lesli_support/tickets_controller.rb', line 37

def index
    respond_to do |format|
        format.html { }
        format.json do
            #respond_with_successful(TicketService.new(current_user, query).index)
            respond_with_pagination(TicketService.new(current_user, query).index)
        end
    end
end

#newObject



56
57
# File 'app/controllers/lesli_support/tickets_controller.rb', line 56

def new
end

#showObject



47
48
49
50
51
52
53
54
# File 'app/controllers/lesli_support/tickets_controller.rb', line 47

def show
    respond_to do |format|
        format.html { }
        format.json do
            respond_with_successful(@ticket.show)
        end
    end
end

#updateObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/controllers/lesli_support/tickets_controller.rb', line 72

def update

    respond_with_successful(@ticket.update(ticket_params))

    # return respond_with_not_found unless @ticket
    # return respond_with_unauthorized unless @ticket.is_editable_by?(current_user, bypass_status: true)

    # # When the ticket is closed, the only available field for update is the status
    # update_params = ticket_params
    # if ["completed_successfully", "completed_unsuccessfully"].include? @ticket.status&.status_type
    #     update_params = completed_ticket_params
    # end

    # if @ticket.check_workflow_transitions(current_user, update_params)
    #     ticket_update_response = TicketServices.update(current_user, @ticket, update_params)

    #     @ticket = ticket_update_response.payload
    #     if ticket_update_response.successful?
    #         respond_with_successful(@ticket.show(current_user, @query))
    #     else
    #         respond_with_error(@ticket.errors.full_messages.to_sentence)
    #     end
    # else
    #     respond_with_error(@ticket.errors.full_messages.to_sentence)
    # end
end