Files
api/services/nginx/app/routes/machineButtonPressRoute.php
T
Jeppe Bundgaard d53dd7645b Add POST route for completing order bookings with authentication and permissions
- Introduced `/order-bookings/complete` route to allow marking bookings as complete.
- Implemented authentication checks and department-level access control.
- Added response handling for successful completion or non-existing bookings.
- Commented out Slack notification in machine button press route for future review.
2025-11-10 12:03:04 +01:00

44 lines
1.6 KiB
PHP

<?php
namespace routes;
use classes\authentication;
use classes\slack;
use objects\customer_vehicles_o;
use objects\logs_o;
use objects\orders_o;
use objects\plate_scans_o;
use objects\users_o;
use traits\route_t;
class machineButtonPressRoute
{
use route_t;
public function run(): void
{
self::get('/relay/button/press/post', function () {
/**
* This is here because the post method is not supported by the software some of the cameras are running on.
*/
global $response;
self::requirePlateScannerAuth();
$plate_scanner = (new authentication())->get_plate_scanner();
self::requireParameters(['token']);
// Validate the token
self::requireType('token', 'string');
self::requireMinLength('token', 1);
self::requireMaxLength('token', 100);
// TODO: Implement action
//$slack = new slack();
//$slack->send_department_booking_notification((int)$plate_scanner->department_id->value(), 'Button was pressed on the machine with the plate scanner: ' . $plate_scanner->id);
// Log the incident
(new logs_o())->add('relay', $plate_scanner->department_id->value(), 1, 0, 'TRIGGER_BUTTON_PRESS', 'Button was pressed on the machine with the plate scanner: ' . $plate_scanner->id);
// Return a success message
$response->success(['message' => 'Button press recorded.', 'scanner' => $plate_scanner->name->value()], 201);
}, [
'add_button_press' => 'Add a button press'
]);
}
}