Skip to content
Snippets Groups Projects
Commit 67c91345 authored by Pegane Nestor's avatar Pegane Nestor
Browse files

FEAT #7475 update status with array of res_id or Chrono + unit test adaptation

parent 973bc25b
No related branches found
No related tags found
No related merge requests found
......@@ -55,9 +55,7 @@ class ResControllerTest extends TestCase
$response = $resController->create($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
self::$id = $responseBody->resId;
$this->assertInternalType('int', self::$id);
// READ
......@@ -84,15 +82,13 @@ class ResControllerTest extends TestCase
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'resId' => self::$id,
'resId' => [self::$id],
'status' => 'EVIS'
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
$response = $resController->updateStatus($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('success', $responseBody->success);
// READ
......@@ -105,7 +101,7 @@ class ResControllerTest extends TestCase
$request = \Slim\Http\Request::createFromEnvironment($environment);
$aArgs = [
'resId' => self::$id
'resId' => [self::$id]
];
$fullRequest = \httpRequestCustom::addContentInBody($aArgs, $request);
......
......@@ -124,46 +124,19 @@ class ResController
$data['historyMessage'] = _UPDATE_STATUS;
}
$check = Validator::stringType()->notEmpty()->validate($data['chrono']) || Validator::intVal()->notEmpty()->validate($data['resId']) || Validator::stringType()->notEmpty()->validate($data['resId']);
$check = Validator::arrayType()->notEmpty()->validate($data['chrono']) || Validator::arrayType()->notEmpty()->validate($data['resId']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['status']);
$check = $check && Validator::stringType()->notEmpty()->validate($data['historyMessage']);
if (!$check) {
return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
}
if(strpos($data['resId'],',')!==false){
$resIds = explode(',', $data['resId']);
foreach($resIds as $resId){
if (!empty($data['chrono'])) {
$document = ResModel::getResIdByAltIdentifier(['altIdentifier' => $data['chrono']]);
} else {
$document = ResModel::getById(['resId' => $resId, 'select' => ['res_id']]);
}
if (empty($document)) {
return $response->withStatus(400)->withJson(['errors' => _DOCUMENT_NOT_FOUND]);
}
if (!ResController::hasRightByResId(['resId' => $document['res_id'], 'userId' => $GLOBALS['userId']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
ResModel::update(['set' => ['status' => $data['status']], 'where' => ['res_id = ?'], 'data' => [$resId]]);
HistoryController::add([
'tableName' => 'res_letterbox',
'recordId' => $document['res_id'],
'eventType' => 'UP',
'info' => $data['historyMessage'],
'moduleId' => 'apps',
'eventId' => 'resup',
]);
}
} else {
$identifiers = !empty($data['chrono'])? $data['chrono']: $data['resId'] ;
foreach($identifiers as $id){
if (!empty($data['chrono'])) {
$document = ResModel::getResIdByAltIdentifier(['altIdentifier' => $data['chrono']]);
$document = ResModel::getResIdByAltIdentifier(['altIdentifier' => $id]);
} else {
$document = ResModel::getById(['resId' => $data['resId'], 'select' => ['res_id']]);
$document = ResModel::getById(['resId' => $id, 'select' => ['res_id']]);
}
if (empty($document)) {
return $response->withStatus(400)->withJson(['errors' => _DOCUMENT_NOT_FOUND]);
......@@ -172,8 +145,9 @@ class ResController
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
ResModel::update(['set' => ['status' => $data['status']], 'where' => ['res_id = ?'], 'data' => [$document['res_id']]]);
HistoryController::add([
'tableName' => 'res_letterbox',
'recordId' => $document['res_id'],
......@@ -182,11 +156,13 @@ class ResController
'moduleId' => 'apps',
'eventId' => 'resup',
]);
}
}
return $response->withJson(['success' => 'success']);
}
//EXTERNAL INFOS
public function isLock(Request $request, Response $response, array $aArgs)
{
return $response->withJson(ResModel::isLock(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']]));
......
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