Guillermo - path and tests staff/last-events [skip ci]
This commit is contained in:
parent
a0d1c401b8
commit
af4853ed51
|
@ -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();
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue