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.
This commit is contained in:
@@ -31,8 +31,8 @@ class machineButtonPressRoute
|
||||
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);
|
||||
//$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
|
||||
|
||||
@@ -249,6 +249,38 @@ class orderBookingRoute
|
||||
]
|
||||
);
|
||||
|
||||
$this->post('/order-bookings/complete', function () {
|
||||
// Require the user to be logged in
|
||||
global $response;
|
||||
/**
|
||||
* Parameters
|
||||
*/
|
||||
$object = self::getTargetObject();
|
||||
/**
|
||||
* Authentication
|
||||
*/
|
||||
$user = (new authentication())->get_user();
|
||||
/**
|
||||
* Permissions
|
||||
*/
|
||||
self::requireDepartmentAccess((int)$object->department->value());
|
||||
if (!$object || !$object->exists()) {
|
||||
$response->error('Order booking does not exist.', 400);
|
||||
}
|
||||
/**
|
||||
* Complete the booking
|
||||
*/
|
||||
$object->completeBooking((int)$user->id->value());
|
||||
/**
|
||||
* Return the object
|
||||
*/
|
||||
$response->success($object->asArray());
|
||||
},
|
||||
[
|
||||
'complete_bookings' => 'Permission to complete order bookings.'
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user