Add support for vehicle reference field

Introduce a new "reference" field for vehicles to allow storing and validating additional information. Updates include parameter handling, validation, and database integration for creating, modifying, and retrieving the "reference" field.
This commit is contained in:
Jepp9350
2025-05-06 09:09:17 +02:00
parent be9ba1a2fa
commit b1ba8a2e34
2 changed files with 36 additions and 2 deletions
+31 -1
View File
@@ -126,6 +126,20 @@ class vehiclesRoute
}
}
}
$reference = null;
// Check if the reference is set
if (self::isParametersSet([
'reference',
])) {
// If the reference is not empty, check if it is valid
if (!empty(self::getParameter('reference'))) {
// Check if the reference is valid
$reference = (string)self::getParameter('reference');
self::requireType($reference, self::type_string());
self::requireMinLength('reference', 1);
self::requireMaxLength('reference', 255);
}
}
// Validate the parameters
self::requireType(
self::getParameter('reg'),
@@ -149,7 +163,8 @@ class vehiclesRoute
$target_user->customer_number->value(),
$type,
$reg,
$subscription ? 1 : 0
$subscription ? 1 : 0,
$reference
);
// Log the incident
@@ -239,6 +254,21 @@ class vehiclesRoute
// Set the wash subscription
$vehicle->wash_subscription->set($subscription ? 1 : 0);
}
if (self::isParametersSet(['reference'])) {
// Check if the reference is set to null/empty
if (empty(self::getParameter('reference'))) {
// Set the reference to null
$vehicle->reference->nullify();
} else {
// Check if the reference is valid
$reference = (string)self::getParameter('reference');
self::requireType($reference, self::type_string());
self::requireMinLength('reference', 1);
self::requireMaxLength('reference', 255);
// Set the reference
$vehicle->reference->set($reference);
}
}
// Return the vehicle
$response->success(
$vehicle->asArray()