fix(api): log new order id when POST /orders succeeds (#374)

Merges api PR #374.
This commit is contained in:
Jeppe B
2026-08-16 13:05:25 +02:00
committed by GitHub
parent 5cde8103f9
commit 4430345831
2 changed files with 18 additions and 1 deletions
+1 -1
View File
@@ -237,7 +237,7 @@ class ordersRoute
$order->setPendingHandheldIndicator(); $order->setPendingHandheldIndicator();
} }
// Log the incident // Log the incident
(new logs_o())->add('orders', $data['department_id'], 1, $user->id, 'ADD_ORDER', 'Successfully added an order (ID: ' . $data['department_id'] . ')'); (new logs_o())->add('orders', $data['department_id'], 1, $user->id, 'ADD_ORDER', 'Successfully added an order (ID: ' . (int)$order->id . ')');
// Return a success message, containing the orders array // Return a success message, containing the orders array
$response->success($order->asArray()); $response->success($order->asArray());
} else { } else {
@@ -0,0 +1,17 @@
<?php
it('logs the newly created order id (not the department id) when POST /orders succeeds', function (): void {
$routeFile = app_path('routes/ordersRoute.php');
$content = file_get_contents($routeFile);
expect($content)->not->toBeFalse();
// The POST /orders handler must log the id of the order that was just
// persisted by addArray(), not the department id from the request body.
// Without this, the audit trail for the "check-in creates 0-orders" bug
// is useless — every successful create logs the wrong identifier.
expect($content)->toContain("'Successfully added an order (ID: ' . (int)\$order->id . ')'");
// Guard against the previous copy/paste regression reappearing.
expect($content)->not->toContain("'Successfully added an order (ID: ' . \$data['department_id'] . ')'");
});