diff --git a/server/controllers/ticket.php b/server/controllers/ticket.php index ea2a38da..53f43fe0 100755 --- a/server/controllers/ticket.php +++ b/server/controllers/ticket.php @@ -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(); diff --git a/server/controllers/ticket/add-tag.php b/server/controllers/ticket/add-tag.php new file mode 100644 index 00000000..0f5e1e79 --- /dev/null +++ b/server/controllers/ticket/add-tag.php @@ -0,0 +1,60 @@ + '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(); + } +} diff --git a/server/controllers/ticket/create-tag.php b/server/controllers/ticket/create-tag.php index e632319d..8324d7fc 100644 --- a/server/controllers/ticket/create-tag.php +++ b/server/controllers/ticket/create-tag.php @@ -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 * diff --git a/server/models/Tag.php b/server/models/Tag.php index 7d1ea08c..6aa66d6d 100644 --- a/server/models/Tag.php +++ b/server/models/Tag.php @@ -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 + ]; + } } } diff --git a/server/models/Ticket.php b/server/models/Ticket.php index bf927c81..1530a888 100755 --- a/server/models/Ticket.php +++ b/server/models/Ticket.php @@ -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) ]; }