guillermo- path- tickets-change-department [skip ci]

This commit is contained in:
ivan 2016-10-15 01:32:44 -03:00
parent be586ddf2f
commit ea586072eb
3 changed files with 63 additions and 0 deletions

View File

@ -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();

View File

@ -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();
}
}

View File

@ -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