diff --git a/server/controllers/staff.php b/server/controllers/staff.php index 64c583ca..1dccf0d1 100644 --- a/server/controllers/staff.php +++ b/server/controllers/staff.php @@ -3,6 +3,7 @@ require_once 'staff/get.php'; require_once 'staff/assign-ticket.php'; require_once 'staff/un-assign-ticket.php'; require_once 'staff/get-tickets.php'; +require_once 'staff/get-new-tickets.php'; $systemControllerGroup = new ControllerGroup(); $systemControllerGroup->setGroupPath('/staff'); @@ -11,5 +12,6 @@ $systemControllerGroup->addController(new GetStaffController); $systemControllerGroup->addController(new AssignStaffController); $systemControllerGroup->addController(new UnAssignStaffController); $systemControllerGroup->addController(new GetTicketStaffController); +$systemControllerGroup->addController(new GetNewTicketsStaffController); $systemControllerGroup->finalize(); \ No newline at end of file diff --git a/server/controllers/staff/get-new-tickets.php b/server/controllers/staff/get-new-tickets.php new file mode 100644 index 00000000..de9e2504 --- /dev/null +++ b/server/controllers/staff/get-new-tickets.php @@ -0,0 +1,26 @@ + 'staff_1', + 'requestData' => [] + ]; + } + public function handler() { + $user = Controller::getLoggedUser(); + $query = ' ('; + foreach ($user->sharedDepartmentList as $department) { + $query .= 'department_id=' . $department->id . ' OR '; + } + $query = substr($query,0,-3); + $query .= ') AND owner_id IS NULL'; + + $ticketList = Ticket::find($query); + + Response::respondSuccess($ticketList->toArray()); + } +} \ No newline at end of file diff --git a/server/models/DataStore.php b/server/models/DataStore.php index 2df06b88..41b19bf8 100644 --- a/server/models/DataStore.php +++ b/server/models/DataStore.php @@ -30,6 +30,11 @@ abstract class DataStore { return $dataStoreList; } + public static function find($query) { + $beanList = RedBean::find(static::TABLE,$query); + + return DataStoreList::getList(ucfirst(static::TABLE),$beanList); + } private static function validateProp($propToValidate) { $validProp = false; diff --git a/tests/init.rb b/tests/init.rb index 17e27979..1ae95b85 100644 --- a/tests/init.rb +++ b/tests/init.rb @@ -30,5 +30,6 @@ require './staff/assign-ticket.rb' require './staff/un-assign-ticket.rb' require './staff/get-tickets.rb' require './ticket/change-priority.rb' +require './staff/get-new-tickets.rb' diff --git a/tests/staff/get-new-tickets.rb b/tests/staff/get-new-tickets.rb new file mode 100644 index 00000000..2ecf7d1d --- /dev/null +++ b/tests/staff/get-new-tickets.rb @@ -0,0 +1,15 @@ +describe '/staff/get-new-tickets' do + request('/user/logout') + Scripts.login($staff[:email], $staff[:password], true) + + it 'should get news tickets' do + + result = request('/staff/get-new-tickets', { + csrf_userid: $csrf_userid, + csrf_token: $csrf_token + }) + + (result['status']).should.equal('success') + (result['data'].size).should.equal(7) + end +end \ No newline at end of file