API path AddTag for tickets

This commit is contained in:
Ivan Diaz 2019-02-21 19:37:53 -03:00
parent 4627405242
commit c970c9923f
5 changed files with 79 additions and 11 deletions

View File

@ -20,5 +20,6 @@ $ticketControllers->addController(new CreateTagController);
$ticketControllers->addController(new EditTagController);
$ticketControllers->addController(new DeleteTagController);
$ticketControllers->addController(new GetTagsController);
$ticketControllers->addController(new AddTagController);
$ticketControllers->finalize();

View File

@ -0,0 +1,60 @@
<?php
use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
/**
* @api {post} /ticket/add-tag Add tag
* @apiVersion 4.3.2
*
* @apiName Add tag
*
* @apiGroup Ticket
*
* @apiDescription This path attaches a new tag to a ticket.
*
* @apiPermission staff1
*
* @apiParam {Number} ticketNumber The number of the ticket which the tag is going to be attached.
* @apiParam {String} tagId The id of the tag to attach.
*
* @apiUse NO_PERMISSION
* @apiUse INVALID_TICKET
* @apiUse INVALID_TAG
*
* @apiSuccess {Object} data Empty object
*
*/
class AddTagController extends Controller {
const PATH = '/add-tag';
const METHOD = 'POST';
public function validations() {
return [
'permission' => 'staff_1',
'requestData' => [
'ticketNumber' => [
'validation' => DataValidator::validTicketNumber(),
'error' => ERRORS::INVALID_TICKET
],
'tagId' => [
'validation' => DataValidator::dataStoreId('tag'),
'error' => ERRORS::INVALID_TAG
]
]
];
}
public function handler() {
$tagId = Controller::request('tagId');
$tag = Tag::getDataStore($tagId);
$ticket = Ticket::getByTicketNumber(Controller::request('ticketNumber'));
if ($ticket->sharedTagList->includesId($tagId)) throw new RequestException(ERRORS::TAG_EXISTS);
$ticket->sharedTagList->add($tag);
$ticket->store();
Response::respondSuccess();
}
}

View File

@ -3,14 +3,14 @@ use Respect\Validation\Validator as DataValidator;
DataValidator::with('CustomValidations', true);
/**
* @api {post} /ticket/add-tag Add tag
* @api {post} /ticket/create-tag Create tag
* @apiVersion 4.3.2
*
* @apiName Add tag
* @apiName Create tag
*
* @apiGroup Ticket
*
* @apiDescription This path add a new tag.
* @apiDescription This path creates a new tag.
*
* @apiPermission staff1
*

View File

@ -10,11 +10,16 @@ class Tag extends DataStore {
'color'
];
}
public function toArray() {
return[
'id'=> $this->id,
'name'=> $this->name,
'color' => $this->color
];
public function toArray($minimized = false) {
if($minimized){
return $this->name;
} else {
return [
'id'=> $this->id,
'name'=> $this->name,
'color' => $this->color
];
}
}
}

View File

@ -49,7 +49,8 @@ class Ticket extends DataStore {
'unreadStaff',
'language',
'authorEmail',
'authorName'
'authorName',
'sharedTagList'
);
}
@ -128,7 +129,8 @@ class Ticket extends DataStore {
'priority' => $this->priority,
'author' => $this->authorToArray(),
'owner' => $this->ownerToArray(),
'events' => $minimized ? [] : $this->eventsToArray()
'events' => $minimized ? [] : $this->eventsToArray(),
'tags' => $this->sharedTagList->toArray(true)
];
}