2016-11-30 18:13:57 +01:00
|
|
|
<?php
|
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
DataValidator::with('CustomValidations', true);
|
|
|
|
|
2016-11-30 21:30:00 +01:00
|
|
|
class GetUserByIdController extends Controller {
|
2016-11-30 18:13:57 +01:00
|
|
|
const PATH = '/get-user';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
|
|
|
|
2016-11-30 18:13:57 +01:00
|
|
|
public function validations() {
|
|
|
|
return [
|
2016-12-14 01:10:49 +01:00
|
|
|
'permission' => 'staff_1',
|
2016-11-30 18:13:57 +01:00
|
|
|
'requestData' => [
|
|
|
|
'userId' => [
|
|
|
|
'validation' => DataValidator::dataStoreId('user'),
|
|
|
|
'error' => ERRORS::INVALID_USER
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
2017-01-16 20:07:53 +01:00
|
|
|
|
|
|
|
if(!Controller::isUserSystemEnabled()) {
|
|
|
|
throw new Exception(ERRORS::USER_SYSTEM_DISABLED);
|
|
|
|
}
|
|
|
|
|
2016-11-30 18:13:57 +01:00
|
|
|
$userId = Controller::request('userId');
|
|
|
|
$user = User::getDataStore($userId);
|
2016-12-14 01:10:49 +01:00
|
|
|
$staff = Controller::getLoggedUser();
|
|
|
|
|
|
|
|
$tickets = new DataStoreList();
|
|
|
|
|
|
|
|
foreach($user->sharedTicketList as $ticket) {
|
|
|
|
if($staff->sharedDepartmentList->includesId($ticket->department->id)) {
|
|
|
|
$tickets->add($ticket);
|
|
|
|
}
|
|
|
|
}
|
2016-11-30 18:13:57 +01:00
|
|
|
|
|
|
|
Response::respondSuccess([
|
|
|
|
'name' => $user->name,
|
|
|
|
'email' => $user->email,
|
|
|
|
'signupDate' => $user->signupDate,
|
2016-12-23 05:56:01 +01:00
|
|
|
'tickets' => $tickets->toArray(),
|
|
|
|
'verified' => !$user->verificationToken
|
2016-11-30 18:13:57 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|