Skip to content
Snippets Groups Projects
Verified Commit a87c7b46 authored by Damien's avatar Damien
Browse files

FEAT #299 Include order by and limit in isRequestValid

parent d7e837fe
No related branches found
No related tags found
No related merge requests found
...@@ -284,11 +284,9 @@ class ResController ...@@ -284,11 +284,9 @@ class ResController
return $response->withStatus(400)->withJson(['errors' => 'Bad Request: limit parameter not valid']); return $response->withStatus(400)->withJson(['errors' => 'Bad Request: limit parameter not valid']);
} }
} }
$orderBy = $data['orderBy'];
$limit = $data['limit'];
$select = explode(',', $data['select']); $select = explode(',', $data['select']);
if (!PreparedClauseController::isRequestValid(['select' => $select,'clause' => $data['clause'], 'orderBy' => $orderBy, 'limit' => $limit, 'userId' => $GLOBALS['userId']])) { if (!PreparedClauseController::isRequestValid(['select' => $select, 'clause' => $data['clause'], 'orderBy' => $data['orderBy'], 'limit' => $data['limit'], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(400)->withJson(['errors' => _INVALID_REQUEST]); return $response->withStatus(400)->withJson(['errors' => _INVALID_REQUEST]);
} }
...@@ -305,7 +303,7 @@ class ResController ...@@ -305,7 +303,7 @@ class ResController
$select[] = 'res_id'; $select[] = 'res_id';
} }
$resources = ResModel::getOnView(['select' => $select, 'where' => $where, 'orderBy' => $orderBy, 'limit' => $limit]); $resources = ResModel::getOnView(['select' => $select, 'where' => $where, 'orderBy' => $data['orderBy'], 'limit' => $data['limit']]);
if ($data['withFile'] === true) { if ($data['withFile'] === true) {
foreach ($resources as $key => $res) { foreach ($resources as $key => $res) {
$path = ResDocserverModel::getSourceResourcePath(['resId' => $res['res_id'], 'resTable' => 'res_letterbox', 'adrTable' => 'null']); $path = ResDocserverModel::getSourceResourcePath(['resId' => $res['res_id'], 'resTable' => 'res_letterbox', 'adrTable' => 'null']);
......
...@@ -24,6 +24,7 @@ class ResModelAbstract ...@@ -24,6 +24,7 @@ class ResModelAbstract
{ {
ValidatorModel::notEmpty($aArgs, ['select']); ValidatorModel::notEmpty($aArgs, ['select']);
ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']);
ValidatorModel::intType($aArgs, ['limit']);
$aResources = DatabaseModel::select([ $aResources = DatabaseModel::select([
'select' => $aArgs['select'], 'select' => $aArgs['select'],
......
...@@ -215,7 +215,8 @@ class PreparedClauseController ...@@ -215,7 +215,8 @@ class PreparedClauseController
{ {
ValidatorModel::notEmpty($aArgs, ['clause', 'userId']); ValidatorModel::notEmpty($aArgs, ['clause', 'userId']);
ValidatorModel::stringType($aArgs, ['clause', 'userId']); ValidatorModel::stringType($aArgs, ['clause', 'userId']);
ValidatorModel::arrayType($aArgs, ['select']); ValidatorModel::arrayType($aArgs, ['select', 'orderBy']);
ValidatorModel::intType($aArgs, ['limit']);
$clause = PreparedClauseController::getPreparedClause(['clause' => $aArgs['clause'], 'userId' => $aArgs['userId']]); $clause = PreparedClauseController::getPreparedClause(['clause' => $aArgs['clause'], 'userId' => $aArgs['userId']]);
...@@ -229,7 +230,7 @@ class PreparedClauseController ...@@ -229,7 +230,7 @@ class PreparedClauseController
} }
try { try {
ResModel::getOnView(['select' => $aArgs['select'], 'where' => [$clause, '1=1']]); ResModel::getOnView(['select' => $aArgs['select'], 'where' => [$clause, '1=1'], 'orderBy' => $aArgs['orderBy'], 'limit' => $aArgs['limit']]);
} catch (\Exception $e) { } catch (\Exception $e) {
return false; return false;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment