uvdesk / api-bundle

API Integration for UVdesk Community Helpdesk System.
MIT License
17 stars 15 forks source link

Fix bug. Allow to fetch tickets (of type actAsType:customer) using th… #17

Closed ricardotormo closed 3 years ago

ricardotormo commented 3 years ago

1. Why is this change necessary?

There's a bug, so when you try to follow the API instructions, in order to fetch tickets, you can't fetch tickets based on a particular customer email.

2. What does this change do, exactly?

The code below has some problems, I guess:

 $customer = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($data['actAsEmail']);
  if ($customer) {
      $json = $repository->getAllCustomerTickets($request->query, $this->container, $customer);
  }

The first line:

 $customer = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($data['actAsEmail']);

Should be:

$email = $request->query->get('actAsEmail');
$customer = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($email);

Because the API should be expecting the get query params.

The third line:

$json = $repository->getAllCustomerTickets($request->query, $this->container, $customer);

Should be:

$json = $ticketRepository->getAllCustomerTickets($request->query, $this->container, $customer);

because $repository is not defined. I guess we want to access the $ticketRepository to get the customers.

3. Please link to the relevant issues (if any).

I opened a issue here: https://github.com/uvdesk/api-bundle/issues/16

It should be mentioned that if you try to filter by agent, that is still not working. If you try this endpoint: {my_localhost_url}/api/v1/tickets?actAsEmail={agent@agentemail.com}&actAsType=agent The API returns:

{
    "status": false,
    "message": "An unexpected error occurred. Please try again later."
}

So I guess there's a problem with this line:

$user = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($data['actAsEmail']);

You could change $data['actAsEmail'] by $request->query->get('actAsEmail') and the error disappear. The problem is that after that, if we try to filter by agent email the API returns all the tickets everytime.

papnoisanjeev commented 3 years ago

@ricardotormo

Thanks for your contribution and reporting this bug to us !! We have added your updates on master branch here.

As your pull request exist with some extra updates so we manually updates your changes in our master directly.