From c743049ed1bc646fbec68313aa6b0725a566e343 Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Thu, 9 Apr 2026 15:32:16 +0700 Subject: [PATCH] fix(testmap): align detail patch operation keys with API docs --- app/Controllers/Test/TestMapController.php | 32 +++++++++++----------- public/api-docs.bundled.yaml | 6 ++-- public/paths/testmap.yaml | 6 ++-- tests/feature/Test/TestMapPatchTest.php | 4 +-- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/Controllers/Test/TestMapController.php b/app/Controllers/Test/TestMapController.php index bd52cb1..f8a76d8 100755 --- a/app/Controllers/Test/TestMapController.php +++ b/app/Controllers/Test/TestMapController.php @@ -95,8 +95,8 @@ class TestMapController extends BaseController { try { $id = $this->model->insert($headerInput); - if ($detailsPayload !== null && !empty($detailsPayload['new'])) { - if (!$this->insertDetailRows($id, $detailsPayload['new'])) { + if ($detailsPayload !== null && !empty($detailsPayload['created'])) { + if (!$this->insertDetailRows($id, $detailsPayload['created'])) { $this->db->transRollback(); return; } @@ -235,35 +235,35 @@ class TestMapController extends BaseController { } if ($this->isDetailOpsPayload($detailsPayload)) { - $newItems = $this->normalizeDetailList($detailsPayload['new'] ?? [], 'details.new'); - if ($newItems === null) { return null; } - $editItems = $this->normalizeDetailList($detailsPayload['edit'] ?? [], 'details.edit'); - if ($editItems === null) { return null; } + $createdItems = $this->normalizeDetailList($detailsPayload['created'] ?? [], 'details.created'); + if ($createdItems === null) { return null; } + $editedItems = $this->normalizeDetailList($detailsPayload['edited'] ?? [], 'details.edited'); + if ($editedItems === null) { return null; } $deletedIds = $this->normalizeDetailIds($detailsPayload['deleted'] ?? []); if ($deletedIds === null) { return null; } - return ['new' => $newItems, 'edit' => $editItems, 'deleted' => $deletedIds]; + return ['created' => $createdItems, 'edited' => $editedItems, 'deleted' => $deletedIds]; } if ($this->isListPayload($detailsPayload)) { $items = $this->normalizeDetailList($detailsPayload, 'details'); if ($items === null) { return null; } - return ['new' => $items, 'edit' => [], 'deleted' => []]; + return ['created' => $items, 'edited' => [], 'deleted' => []]; } if ($this->isAssocArray($detailsPayload)) { $items = $this->normalizeDetailList([$detailsPayload], 'details'); if ($items === null) { return null; } - return ['new' => $items, 'edit' => [], 'deleted' => []]; + return ['created' => $items, 'edited' => [], 'deleted' => []]; } - $this->failValidationErrors('details must be an array of objects or contain new/edit/deleted arrays.'); + $this->failValidationErrors('details must be an array of objects or contain created/edited/deleted arrays.'); return null; } private function applyDetailOperations(int $testMapID, array $operations): bool { - if (!empty($operations['edit']) && !$this->updateDetails($testMapID, $operations['edit'])) { + if (!empty($operations['edited']) && !$this->updateDetails($testMapID, $operations['edited'])) { return false; } @@ -271,7 +271,7 @@ class TestMapController extends BaseController { return false; } - if (!empty($operations['new']) && !$this->insertDetailRows($testMapID, $operations['new'])) { + if (!empty($operations['created']) && !$this->insertDetailRows($testMapID, $operations['created'])) { return false; } @@ -287,7 +287,7 @@ class TestMapController extends BaseController { $prepared = []; foreach ($items as $index => $item) { if (!$this->validateData($item, $this->detailRules)) { - $this->failValidationErrors(['details.new' => $this->validator->getErrors()]); + $this->failValidationErrors(['details.created' => $this->validator->getErrors()]); return false; } $prepared[] = array_merge(['TestMapID' => $testMapID], $item); @@ -302,12 +302,12 @@ class TestMapController extends BaseController { foreach ($items as $index => $detail) { $detailID = $detail['TestMapDetailID'] ?? null; if (!$detailID || !ctype_digit((string) $detailID)) { - $this->failValidationErrors("details.edit[{$index}].TestMapDetailID is required and must be an integer."); + $this->failValidationErrors("details.edited[{$index}].TestMapDetailID is required and must be an integer."); return false; } if (array_key_exists('TestMapID', $detail) && (int) $detail['TestMapID'] !== $testMapID) { - $this->failValidationErrors("details.edit[{$index}] must belong to TestMap {$testMapID}."); + $this->failValidationErrors("details.edited[{$index}] must belong to TestMap {$testMapID}."); return false; } @@ -367,7 +367,7 @@ class TestMapController extends BaseController { private function isDetailOpsPayload(array $payload): bool { - return (bool) array_intersect(array_keys($payload), ['new', 'edit', 'deleted']); + return (bool) array_intersect(array_keys($payload), ['created', 'edited', 'deleted']); } private function isListPayload(array $payload): bool diff --git a/public/api-docs.bundled.yaml b/public/api-docs.bundled.yaml index 157c28a..db3d6bc 100755 --- a/public/api-docs.bundled.yaml +++ b/public/api-docs.bundled.yaml @@ -4216,11 +4216,11 @@ paths: details: description: | Detail payload supports either a flat array/object (treated as new rows) - or an operations object with `new`, `edit`, and `deleted` arrays. + or an operations object with `created`, `edited`, and `deleted` arrays. oneOf: - type: object properties: - new: + created: type: array description: New detail records to insert items: @@ -4236,7 +4236,7 @@ paths: type: string ClientTestName: type: string - edit: + edited: type: array description: Existing detail records to update items: diff --git a/public/paths/testmap.yaml b/public/paths/testmap.yaml index e9a6479..17f7b49 100755 --- a/public/paths/testmap.yaml +++ b/public/paths/testmap.yaml @@ -191,11 +191,11 @@ details: description: | Detail payload supports either a flat array/object (treated as new rows) - or an operations object with `new`, `edit`, and `deleted` arrays. + or an operations object with `created`, `edited`, and `deleted` arrays. oneOf: - type: object properties: - new: + created: type: array description: New detail records to insert items: @@ -211,7 +211,7 @@ type: string ClientTestName: type: string - edit: + edited: type: array description: Existing detail records to update items: diff --git a/tests/feature/Test/TestMapPatchTest.php b/tests/feature/Test/TestMapPatchTest.php index 5e7274c..b9341d4 100755 --- a/tests/feature/Test/TestMapPatchTest.php +++ b/tests/feature/Test/TestMapPatchTest.php @@ -188,13 +188,13 @@ class TestMapPatchTest extends CIUnitTestCase ->call('patch', "{$this->endpoint}/{$testMap['TestMapID']}", [ 'ClientType' => 'WST', 'details' => [ - 'edit' => [ + 'edited' => [ [ 'TestMapDetailID' => $editDetail['TestMapDetailID'], 'ClientTestName' => 'Hemoglobin Updated', ], ], - 'new' => [ + 'created' => [ [ 'HostTestCode' => 'MCV', 'HostTestName' => 'MCV',