Can now get ticket by ID
This commit is contained in:
parent
54cb77b136
commit
215bcca079
@ -188,7 +188,6 @@ class AttachmentHandler {
|
||||
if (count($errorKeys) > 0) {
|
||||
$validationModel = new ValidationModel();
|
||||
$validationModel->errorKeys = $errorKeys;
|
||||
$validationModel->valid = false;
|
||||
throw new ValidationException($validationModel);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class ValidationException extends ApiFriendlyException {
|
||||
* @throws Exception If the validationModel's errorKeys is empty
|
||||
*/
|
||||
function __construct($validationModel) {
|
||||
if (count($validationModel->errorKeys) === 0 || $validationModel->valid) {
|
||||
if (count($validationModel->errorKeys) === 0) {
|
||||
throw new Exception('Tried to throw a ValidationException, but the validation model was valid or had 0 error keys!');
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,8 @@ class Ticket {
|
||||
$ticket->name = $row['name'];
|
||||
if ($row['email'] !== null) {
|
||||
$emails = str_replace(';', ',', $row['email']);
|
||||
$ticket->email = explode(',', strtolower($emails));
|
||||
$emails = explode(',', strtolower($emails));
|
||||
$ticket->email = array_filter($emails);
|
||||
}
|
||||
$ticket->categoryId = intval($row['category']);
|
||||
$ticket->priorityId = intval($row['priority']);
|
||||
|
@ -86,7 +86,6 @@ class TicketCreator {
|
||||
|
||||
if (count($validationModel->errorKeys) > 0) {
|
||||
// Validation failed
|
||||
$validationModel->valid = false;
|
||||
throw new ValidationException($validationModel);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace BusinessLogic\Tickets;
|
||||
|
||||
|
||||
use BusinessLogic\Exceptions\ApiFriendlyException;
|
||||
use BusinessLogic\Exceptions\ValidationException;
|
||||
use BusinessLogic\ValidationModel;
|
||||
use DataAccess\Tickets\TicketGateway;
|
||||
@ -25,9 +26,17 @@ class TicketRetriever {
|
||||
$this->validate($trackingId, $emailAddress, $heskSettings);
|
||||
|
||||
$ticket = $this->ticketGateway->getTicketByTrackingId($trackingId, $heskSettings);
|
||||
if ($ticket === null) {
|
||||
$ticket = $this->ticketGateway->getTicketByMergedTrackingId($trackingId, $heskSettings);
|
||||
|
||||
if ($ticket === null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if ($heskSettings['email_view_ticket'] && !in_array($emailAddress, $ticket->email)) {
|
||||
throw new \Exception("Email '{$emailAddress}' entered in for ticket '{$trackingId}' does not match!");
|
||||
throw new ApiFriendlyException("Email '{$emailAddress}' entered in for ticket '{$trackingId}' does not match!",
|
||||
"Email Does Not Match", 400);
|
||||
}
|
||||
|
||||
return $ticket;
|
||||
|
@ -8,13 +8,7 @@ class ValidationModel {
|
||||
*/
|
||||
public $errorKeys;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $valid;
|
||||
|
||||
function __construct() {
|
||||
$this->errorKeys = [];
|
||||
$this->valid = true;
|
||||
}
|
||||
}
|
@ -6,18 +6,22 @@ use BusinessLogic\Helpers;
|
||||
use BusinessLogic\Tickets\CreateTicketByCustomerModel;
|
||||
use BusinessLogic\Tickets\TicketCreator;
|
||||
use BusinessLogic\Tickets\TicketRetriever;
|
||||
use BusinessLogic\ValidationModel;
|
||||
use Controllers\JsonRetriever;
|
||||
|
||||
|
||||
class CustomerTicketController {
|
||||
/*function get($id) {
|
||||
global $applicationContext, $hesk_settings, $userContext;
|
||||
function get() {
|
||||
global $applicationContext, $hesk_settings;
|
||||
|
||||
$trackingId = isset($_GET['trackingId']) ? $_GET['trackingId'] : null;
|
||||
$emailAddress = isset($_GET['email']) ? $_GET['email'] : null;
|
||||
|
||||
/* @var $ticketRetriever TicketRetriever */
|
||||
/*$ticketRetriever = $applicationContext->get[TicketRetriever::class];
|
||||
$ticketRetriever = $applicationContext->get[TicketRetriever::class];
|
||||
|
||||
output($ticketRetriever->getTicketById($id, $hesk_settings, $userContext));
|
||||
}*/
|
||||
output($ticketRetriever->getTicketByTrackingIdAndEmail($trackingId, $emailAddress, $hesk_settings));
|
||||
}
|
||||
|
||||
function post() {
|
||||
global $applicationContext, $hesk_settings, $userContext;
|
||||
@ -29,17 +33,9 @@ class CustomerTicketController {
|
||||
|
||||
$ticket = $ticketCreator->createTicketByCustomer($this->buildTicketRequestFromJson($jsonRequest), $hesk_settings, $userContext);
|
||||
|
||||
//if ticket is a stageTicket, email user
|
||||
//else if assigned to owner, email new owner
|
||||
//else email all staff
|
||||
|
||||
return output($ticket, 201);
|
||||
}
|
||||
|
||||
function delete($id) {
|
||||
global $applicationContext, $hesk_settings, $userContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $json array
|
||||
* @return CreateTicketByCustomerModel
|
||||
|
@ -90,6 +90,26 @@ class TicketGateway extends CommonDao {
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $trackingId string
|
||||
* @param $heskSettings array
|
||||
* @return Ticket|null
|
||||
*/
|
||||
function getTicketByMergedTrackingId($trackingId, $heskSettings) {
|
||||
$this->init();
|
||||
|
||||
$rs = hesk_dbQuery("SELECT `trackid` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` WHERE `merged` LIKE '%#" . hesk_dbEscape($trackingId) . "#%'");
|
||||
if (hesk_dbNumRows($rs) === 0) {
|
||||
return null;
|
||||
}
|
||||
$row = hesk_dbFetchAssoc($rs);
|
||||
$actualTrackingId = $row['trackid'];
|
||||
|
||||
$this->close();
|
||||
|
||||
return $this->getTicketByTrackingId($actualTrackingId, $heskSettings);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $ticket Ticket
|
||||
* @param $isEmailVerified
|
||||
|
@ -147,6 +147,7 @@ class NewTicketValidatorTest extends TestCase {
|
||||
function testItSupportsMultipleEmails() {
|
||||
//-- Arrange
|
||||
$this->ticketRequest->email = 'something@email.com;another@valid.email';
|
||||
$this->ticketRequest->language = 'English';
|
||||
$this->heskSettings['multi_eml'] = true;
|
||||
|
||||
//-- Act
|
||||
@ -155,7 +156,7 @@ class NewTicketValidatorTest extends TestCase {
|
||||
$this->userContext);
|
||||
|
||||
//-- Assert
|
||||
$this->assertThat($validationModel->valid, $this->isTrue());
|
||||
self::assertThat(count($validationModel->errorKeys), self::equalTo(0));
|
||||
}
|
||||
|
||||
function testItAddsTheProperValidationErrorWhenCategoryIsNotANumber() {
|
||||
|
@ -36,6 +36,20 @@ class TicketRetrieverTest extends TestCase {
|
||||
self::assertThat($actual, self::equalTo($ticket));
|
||||
}
|
||||
|
||||
function testItGetsTheParentTicketIfTheUserEntersInAMergedTicketId() {
|
||||
//-- Arrange
|
||||
$ticket = new Ticket();
|
||||
$trackingId = '12345';
|
||||
$this->ticketGateway->method('getTicketByTrackingId')->willReturn(null);
|
||||
$this->ticketGateway->method('getTicketByMergedTrackingId')->with($trackingId, $this->heskSettings)->willReturn($ticket);
|
||||
|
||||
//-- Act
|
||||
$actual = $this->ticketRetriever->getTicketByTrackingIdAndEmail($trackingId, null, $this->heskSettings);
|
||||
|
||||
//-- Assert
|
||||
self::assertThat($actual, self::equalTo($ticket));
|
||||
}
|
||||
|
||||
function testItChecksTheTicketsEmailIfThePageRequiresIt() {
|
||||
//-- Arrange
|
||||
$ticket = new Ticket();
|
||||
|
Loading…
x
Reference in New Issue
Block a user