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

[REFACTORING] Return id created when create and update listTemplate

parent cedb3729
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,7 @@ class ListTemplateControllerTest extends TestCase
$response = $listTemplateController->create($fullRequest, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('success', $responseBody->success);
$this->assertInternalType('int', $responseBody->id);
// READ
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
......@@ -136,7 +136,7 @@ class ListTemplateControllerTest extends TestCase
$response = $listTemplateController->update($fullRequest, new \Slim\Http\Response(), ['id' => self::$id]);
$responseBody = json_decode((string)$response->getBody());
$this->assertSame('success', $responseBody->success);
$this->assertInternalType('int', $responseBody->id);
// READ
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
......
......@@ -97,8 +97,9 @@ class ListTemplateController
return $response->withStatus(400)->withJson(['errors' => $checkItems['errors']]);
}
$listTemplateId = null;
foreach ($data['items'] as $item) {
ListTemplateModel::create([
$listTemplateId = ListTemplateModel::create([
'object_id' => $data['object_id'],
'object_type' => $data['object_type'],
'title' => $data['title'],
......@@ -119,7 +120,7 @@ class ListTemplateController
'eventId' => 'listTemplateCreation',
]);
return $response->withJson(['success' => 'success']);
return $response->withJson(['id' => $listTemplateId]);
}
public function update(Request $request, Response $response, array $aArgs)
......@@ -158,8 +159,10 @@ class ListTemplateController
'where' => ['object_id = ?', 'object_type = ?'],
'data' => [$listTemplates[0]['object_id'], $listTemplates[0]['object_type']]
]);
$listTemplateId = null;
foreach ($data['items'] as $item) {
ListTemplateModel::create([
$listTemplateId = ListTemplateModel::create([
'object_id' => $listTemplates[0]['object_id'],
'object_type' => $listTemplates[0]['object_type'],
'title' => $data['title'],
......@@ -180,7 +183,7 @@ class ListTemplateController
'eventId' => 'listTemplateModification',
]);
return $response->withJson(['success' => 'success']);
return $response->withJson(['id' => $listTemplateId]);
}
public function delete(Request $request, Response $response, array $aArgs)
......
......@@ -65,9 +65,12 @@ class ListTemplateModelAbstract
ValidatorModel::stringType($aArgs, ['object_id', 'object_type', 'item_id', 'item_type', 'title', 'description']);
ValidatorModel::intVal($aArgs, ['sequence']);
$nextSequenceId = DatabaseModel::getNextSequenceValue(['sequenceId' => 'listmodels_id_seq']);
DatabaseModel::insert([
'table' => 'listmodels',
'columnsValues' => [
'id' => $nextSequenceId,
'object_id' => $aArgs['object_id'],
'object_type' => $aArgs['object_type'],
'sequence' => $aArgs['sequence'],
......@@ -76,11 +79,11 @@ class ListTemplateModelAbstract
'item_mode' => $aArgs['item_mode'],
'title' => $aArgs['title'],
'description' => $aArgs['description'],
'visible' => 'Y',
'visible' => 'Y'
]
]);
return true;
return $nextSequenceId;
}
public static function update(array $aArgs)
......
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