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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user