예제 #1
0
def remove(current_user, workspaceId, projectId):
    """
        Remove Ticket By Id
    """
    if request.content_type == 'application/json':
        post_data = request.get_json()
        if 'id' not in post_data:
            return response('failed', 'Ticket Id required', 402)
        else:
            ticket = Ticket.get_by_id(post_data.get('id'))
            if ticket:
                ticket.delete_ticket(current_user)
                res_payload = {
                    'id': ticket._id,
                    'firstName': ticket.firstName,
                    'lastName': ticket.lastName,
                    'category': ticket.category,
                    'status': ticket.status,
                    'notes': ticket.notes,
                    'channel': ticket.channel,
                    'createdOn': ticket.createdOn,
                    'phone': ticket.phone,
                    'email': ticket.email
                }
                return response_with_obj('success',
                                         'Ticket deleted successfully',
                                         res_payload, 200)
            else:
                response('failed', 'Ticket not found', 402)

    else:
        return response('failed', 'Content-type must be json', 402)
예제 #2
0
    def patch(self, ticket_id):
        """
        Update a single ticket
        """

        # To do check if ticket is admin
        schema = TicketSchema(partial=True)

        update_data = request.get_json()

        validated_update_data, errors = schema.load(update_data)

        if errors:
            return dict(status="fail", message=errors), 400

        ticket = Ticket.get_by_id(ticket_id)

        if not ticket:
            return dict(status="fail",
                        message=f"Ticket with id {ticket_id} not found"), 404

        updated_ticket = Ticket.update(ticket, **validated_update_data)

        if not updated_ticket:
            return dict(status='fail', message='Internal Server Error'), 500

        return dict(status="success",
                    message="Ticket updated successfully"), 200
예제 #3
0
    def delete(self, ticket_id):
        """
        Delete a single ticket
        """

        ticket = Ticket.get_by_id(ticket_id)

        if not ticket:
            return dict(status="fail",
                        message=f"Ticket with id {ticket_id} not found"), 404

        deleted_ticket = ticket.delete()

        if not deleted_ticket:
            return dict(status='fail', message='Internal Server Error'), 500

        return dict(status='success', message="Successfully deleted"), 200
예제 #4
0
    def get(self, ticket_id):
        """
        Getting individual ticket
        """
        schema = TicketSchema()

        ticket = Ticket.get_by_id(ticket_id)

        if not ticket:
            return dict(status="fail",
                        message=f"Ticket with id {ticket_id} not found"), 404

        ticket_data, errors = schema.dumps(ticket)

        if errors:
            return dict(status="fail", message=errors), 500

        return dict(status='success',
                    data=dict(ticket=json.loads(ticket_data))), 200