Add password reset endpoint and refactor booking count logic

- Introduce `POST /auth/password-reset/request` endpoint in test and `authRoute.php`.
- Refactor bookings route to use a new method `getDailyUnfulfilledBookingsCountForDepartment`
This commit is contained in:
Jeppe Bundgaard
2026-01-22 14:38:54 +01:00
parent 29c53c3b70
commit 64faea9324
4 changed files with 35 additions and 7 deletions
@@ -531,4 +531,21 @@ class order_bookings_o extends db
return !empty($this->order_id->value());
}
public function getDailyUnfulfilledBookingsCountForDepartment(int $department_id, string $date = null): int
{
global /** @var db $db */
$db;
if ($date === null) {
$date = date('Y-m-d');
}
// Sanitize date
$date = date('Y-m-d', strtotime($date));
$order_ids = self::getFieldsWhere([
'department' => (int)$department_id,
'DATE(datetime)' => $date,
'order_id' => null,
], ['id']);
return count($order_ids);
}
}
+7
View File
@@ -28,6 +28,13 @@ class authRoute
if (!is_array($data)) {
$data = [];
}
self::requireParameters(['customer_number', 'password']);
self::requireType((int)$data['customer_number'], $this->type_int());
self::requireMinValue((int)$data['customer_number'], 1);
self::requireType((string)$data['password'], $this->type_string());
self::requireMinLength('password', 1);
$data['customer_number'] = (int)$data['customer_number'];
$data['password'] = (string)$data['password'];
// Check if the customer number, and password are set
if (!isset($data['customer_number']) || empty($data['customer_number']) || !is_numeric($data['customer_number']) || $data['customer_number'] < 1) {
$response->error('Customer number is required', 400);
+2 -7
View File
@@ -9,6 +9,7 @@ use classes\wash_certificate_store;
use objects\bookings_o;
use objects\departments_o;
use objects\logs_o;
use objects\order_bookings_o;
use traits\route_t;
class bookingsRoute
@@ -265,12 +266,6 @@ class bookingsRoute
$response->error('Department ID must be a number', 400);
}
// Check if the result is cached, if so, we don't need to query the database
if (redis->get_department_booking_count((int)$this->fromRequest('department_id'))) {
$response->add_meta('cached', true);
$response->success(
redis->get_department_booking_count((int)$this->fromRequest('department_id'))
);
}
// Check if the department exists
if (!(new departments_o())->selectId((int)$this->fromRequest('department_id'))->exists()) {
$response->error('Department not found', 404);
@@ -279,7 +274,7 @@ class bookingsRoute
(new logs_o())->add('bookings', 'global', 1, $user->id, 'LIST_DEPARTMENT_BOOKINGS_COUNT', 'Successfully listed department bookings');
// Return the list of departments
$response->success(
(new bookings_o())->getDepartmentBookingsUnfulfilledCount((int)$this->fromRequest('department_id'))
(int)(new order_bookings_o())->getDailyUnfulfilledBookingsCountForDepartment((int)$this->fromRequest('department_id'))
);
} else {
// Log the incident
+9
View File
@@ -44,6 +44,15 @@ Authorization: Bearer e9d4359673de64f6a9bc4231bf50ac9f5726ad5b3ee6fcad5f8ebbb206
"safety_seal": 123456
}
### POST request password reset
POST https://api.truckwash.dk:4433/auth/password-reset/request
Accept: application/json
Content-Type: application/json
{
"customer_number": 12345679
}
###
### POST request to order bookings
POST https://api.truckwash.dk:4433/order-bookings