guillermo- path- tickets-change-department [skip ci]
This commit is contained in:
parent
be586ddf2f
commit
ea586072eb
|
@ -6,6 +6,7 @@ include 'ticket/add-custom-response.php';
|
|||
include 'ticket/delete-custom-response.php';
|
||||
include 'ticket/edit-custom-response.php';
|
||||
include 'ticket/get-custom-responses.php';
|
||||
include 'ticket/change-department.php';
|
||||
|
||||
$ticketControllers = new ControllerGroup();
|
||||
$ticketControllers->setGroupPath('/ticket');
|
||||
|
@ -17,5 +18,6 @@ $ticketControllers->addController(new AddCustomResponseController);
|
|||
$ticketControllers->addController(new DeleteCustomResponseController);
|
||||
$ticketControllers->addController(new EditCustomResponseController);
|
||||
$ticketControllers->addController(new GetCustomResponsesController);
|
||||
$ticketControllers->addController(new ChangeDepartmentController);
|
||||
|
||||
$ticketControllers->finalize();
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
DataValidator::with('CustomValidations', true);
|
||||
|
||||
class ChangeDepartmentController extends Controller {
|
||||
const PATH = '/change-department';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'staff_1',
|
||||
'requestData' => [
|
||||
'ticketNumber' => [
|
||||
'validation' => DataValidator::validTicketNumber(),
|
||||
'error' => ERRORS::INVALID_TICKET
|
||||
],
|
||||
'departmentId' => [
|
||||
'validation' => DataValidator::dataStoreId('department'),
|
||||
'error' => ERRORS::INVALID_DEPARTMENT
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$ticketNumber = Controller::request('ticketNumber');
|
||||
$departmentId = Controller::request('departmentId');
|
||||
$ticket = Ticket::getByTicketNumber($ticketNumber);
|
||||
$department = Department::getDataStore($departmentId);
|
||||
$user = Controller::getLoggedUser();
|
||||
|
||||
if($ticket->owner && $ticket->owner->id !== $user->id){
|
||||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
return;
|
||||
}
|
||||
|
||||
$ticket->department = $department;
|
||||
$ticket->store();
|
||||
Response::respondSuccess();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
describe '/ticket/change-department' do
|
||||
request('/user/logout')
|
||||
Scripts.login($staff[:email], $staff[:password], true)
|
||||
|
||||
#TODO: Create tests
|
||||
|
||||
it 'should change department if everything is okey' do
|
||||
|
||||
result = request('/ticket/change-department', {
|
||||
ticketNumber:1,
|
||||
departmentId:2,
|
||||
csrf_userid: $csrf_userid,
|
||||
csrf_token: $csrf_token
|
||||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
|
||||
ticket = $database.getRow('ticket', 1 , 'id')
|
||||
(ticket['department']).should.equal('2')
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue