Guillermo - path and tests staff/last-events [skip ci]

This commit is contained in:
AntonyAntonio 2017-01-03 18:52:18 -03:00
parent a0d1c401b8
commit af4853ed51
4 changed files with 50 additions and 2 deletions

View File

@ -10,6 +10,7 @@ require_once 'staff/add.php';
require_once 'staff/get-all.php';
require_once 'staff/delete.php';
require_once 'staff/edit.php';
require_once 'staff/last-events.php';
$systemControllerGroup = new ControllerGroup();
$systemControllerGroup->setGroupPath('/staff');
@ -25,5 +26,6 @@ $systemControllerGroup->addController(new AddStaffController);
$systemControllerGroup->addController(new GetAllStaffController);
$systemControllerGroup->addController(new DeleteStaffController);
$systemControllerGroup->addController(new EditStaffController);
$systemControllerGroup->addController(new LastEventsStaffController);
$systemControllerGroup->finalize();

View File

@ -0,0 +1,34 @@
<?php
use Respect\Validation\Validator as DataValidator;
class LastEventsStaffController extends Controller {
const PATH = '/last-events';
public function validations() {
return [
'permission' => 'staff_1',
'requestData' => [
'page' => [
'validation' => DataValidator::numeric(),
'error' => ERRORS::INVALID_PAGE
]
]
];
}
public function handler() {
$page = Controller::request('page');
$user = Controller::getLoggedUser();
$query = ' (';
foreach ($user->sharedTicketList as $ticket) {
$query .= 'ticket_id =' . $ticket->id . ' OR ';
}
$query = substr($query,0,-3);
$query .= ') ORDER BY id desc LIMIT ? OFFSET ?' ;
$eventList = Ticketevent::find($query, [10, 10*($page-1)+1]);
Response::respondSuccess($eventList->toArray());
}
}

View File

@ -58,4 +58,17 @@ class Ticketevent extends DataStore {
return new NullDataStore();
}
public function toArray() {
$user = ($this->authorUser instanceof User) ? $this->authorUser : $this->authorStaff;
return [
'type' => $this->type,
'ticketNumber' => $this->ticket->ticketNumber,
'author' => [
'name' => $user->name,
'id' => $user->id
]
];
}
}

View File

@ -47,5 +47,4 @@ require './staff/get-all.rb'
require './system/add-department.rb'
require './system/edit-department.rb'
require './system/delete-department.rb'
require './staff/last-events.rb'