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:
@@ -16,6 +16,7 @@ class customer_vehicles_o extends db
|
||||
public object_property $reg; // The registration number of the vehicle
|
||||
public object_property $wash_subscription; // The wash subscription of the vehicle (boolean)
|
||||
public object_property $notes; // The notes of the vehicle
|
||||
public object_property $reference; // The reference of the vehicle
|
||||
public object_property $deleted_at; // The timestamp of when the record was "deleted"
|
||||
|
||||
/**
|
||||
@@ -52,6 +53,7 @@ class customer_vehicles_o extends db
|
||||
'customer_name' => (string)(new users_o())->getCustomerName((int)$this->customer_id->value()),
|
||||
'type' => (int)$this->type->value(),
|
||||
'reg' => (string)$this->reg->value(),
|
||||
'reference' => ($this->reference->value() ? (string)$this->reference->value() : null),
|
||||
'wash_subscription' => $wash_subscription,
|
||||
'addons' => [
|
||||
'enabled' => count($addons),
|
||||
@@ -160,7 +162,7 @@ class customer_vehicles_o extends db
|
||||
/**
|
||||
* @throws Exception If the creation of the object fails
|
||||
*/
|
||||
public function add(int $customer_number, int $type, string $reg, bool $subscription): void
|
||||
public function add(int $customer_number, int $type, string $reg, bool $subscription, string|null $reference = null): void
|
||||
{
|
||||
global $db, $response;
|
||||
$tmp_id = self::add_object([
|
||||
@@ -168,6 +170,7 @@ class customer_vehicles_o extends db
|
||||
'type' => (int)$type,
|
||||
'reg' => (string)$reg,
|
||||
'wash_subscription' => (bool)$subscription ? 1 : 0,
|
||||
'reference' => ($reference ? (string)$reference : null),
|
||||
]);
|
||||
self::select((int)$tmp_id);
|
||||
self::objectChanged();
|
||||
@@ -189,6 +192,7 @@ class customer_vehicles_o extends db
|
||||
$this->customer_id = new object_property($this->table, $this->id, 'customer_id', 'int', true);
|
||||
$this->type = new object_property($this->table, $this->id, 'type', 'int', true);
|
||||
$this->reg = new object_property($this->table, $this->id, 'reg', 'string', true);
|
||||
$this->reference = new object_property($this->table, $this->id, 'reference', 'string', false);
|
||||
$this->wash_subscription = new object_property($this->table, $this->id, 'wash_subscription', 'bool', false);
|
||||
$this->deleted_at = new object_property($this->table, $this->id, 'deleted_at', 'timestamp', false);
|
||||
}
|
||||
|
||||
@@ -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