Merges search-tickets with get-all-tickets

This commit is contained in:
Maxi Redigonda 2018-10-27 17:42:45 -03:00
parent 5405f2b9ec
commit ac11db5505
2 changed files with 21 additions and 9 deletions

View File

@ -32,14 +32,12 @@ export default {
}; };
}, },
retrieveAllTickets(page = 1, closed = 0) { retrieveAllTickets(page = 1, query = '', closed = 0) {
console.log('Closed is:');
console.log(closed);
return { return {
type: 'ALL_TICKETS', type: 'ALL_TICKETS',
payload: API.call({ payload: API.call({
path: '/staff/get-all-tickets', path: '/staff/get-all-tickets',
data: {page, closed} data: {page, query, closed}
}) })
}; };
}, },

View File

@ -2,18 +2,19 @@
use Respect\Validation\Validator as DataValidator; use Respect\Validation\Validator as DataValidator;
/** /**
* @api {post} /staff/get-all-tickets Get all tickets * @api {post} /staff/get-all-tickets Get all tickets according to search
* @apiVersion 4.3.0 * @apiVersion 4.3.0
* *
* @apiName Get all tickets * @apiName Get all tickets
* *
* @apiGroup Staff * @apiGroup Staff
* *
* @apiDescription This path retrieves all tickets. * @apiDescription This path retrieves all tickets according to search and opened/closed filters.
* *
* @apiPermission staff1 * @apiPermission staff1
* *
* @apiParam {Number} page The page number. * @apiParam {Number} page The page number.
* @apiParam {String} query Query string to search.
* @apiParam {Boolean} closed Include closed tickets. * @apiParam {Boolean} closed Include closed tickets.
* *
* @apiUse NO_PERMISSION * @apiUse NO_PERMISSION
@ -59,11 +60,24 @@ class GetAllTicketsStaffController extends Controller {
private function getTicketList() { private function getTicketList() {
$page = Controller::request('page'); $page = Controller::request('page');
$query = $this->getStaffDepartmentsQueryFilter(); $query = $this->getSearchQuery();
$query .= $this->getStaffDepartmentsQueryFilter();
$query .= $this->getClosedFilter(); $query .= $this->getClosedFilter();
$query .= ' ORDER BY id DESC LIMIT 10 OFFSET ' . (($page-1)*10); $query .= "ORDER BY CASE WHEN (title LIKE ?) THEN 1 ELSE 2 END ASC LIMIT 10 OFFSET " . (($page-1)*10);
return Ticket::find($query); return Ticket::find($query, [
Controller::request('query') . '%',
'%' . Controller::request('query') . '%',
Controller::request('query') . '%'
]);
}
private function getSearchQuery() {
$page = Controller::request('page');
$query = " (title LIKE ? OR title LIKE ?) AND ";
return $query;
} }
private function getTotalPages() { private function getTotalPages() {