fix(testmap): align detail patch operation keys with API docs
This commit is contained in:
parent
7e38622070
commit
c743049ed1
@ -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
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user