Allow vehicle type to be unset and improve related checks
Updated logic to allow vehicle type to be set to 0 and handle related subscription behavior. Added safeguards to prevent setting subscriptions when type is unset. Introduced `isPlateSeenBefore` in `orders_o` and enhanced `plateScansRoute` to include `seen_before` data.
This commit is contained in:
@@ -226,20 +226,28 @@ class vehiclesRoute
|
||||
$type = (int)self::getParameter('type');
|
||||
// Make sure the type is an integer
|
||||
self::requireType($type, self::type_int());
|
||||
self::requireMinValue($type, 1);
|
||||
// Make sure the type is a valid type
|
||||
$products_o = new products_o();
|
||||
$products_o->select((int)$type);
|
||||
if (!$products_o->exists() || !$products_o->subscription_allowed->value()) {
|
||||
// Log the incident
|
||||
(new logs_o())->add('vehicles', 'global', 1, $user->id, 'EDIT_VEHICLE', 'Invalid type');
|
||||
// Return an error
|
||||
$response->error('Invalid type', 400);
|
||||
self::requireMinValue($type, 0);
|
||||
// Make sure the type is a valid type (If it isn't 0)
|
||||
if ($type === 0) {
|
||||
// Set the type to null
|
||||
$vehicle->type->set(0);
|
||||
// Turn off the subscription
|
||||
$vehicle->wash_subscription->set(0);
|
||||
return;
|
||||
} else {
|
||||
$products_o = new products_o();
|
||||
$products_o->select((int)$type);
|
||||
if (!$products_o->exists() || !$products_o->subscription_allowed->value()) {
|
||||
// Log the incident
|
||||
(new logs_o())->add('vehicles', 'global', 1, $user->id, 'EDIT_VEHICLE', 'Invalid type');
|
||||
// Return an error
|
||||
$response->error('Invalid type', 400);
|
||||
}
|
||||
// Set the type
|
||||
$vehicle->type->set(
|
||||
(int)$type
|
||||
);
|
||||
}
|
||||
// Set the type
|
||||
$vehicle->type->set(
|
||||
(int)$type
|
||||
);
|
||||
}
|
||||
if (self::isParametersSet(['reg'])) {
|
||||
$reg = (string)self::getParameter('reg');
|
||||
@@ -252,6 +260,11 @@ class vehiclesRoute
|
||||
if (self::isParametersSet(['wash_subscription'])) {
|
||||
$subscription = (bool)self::getParameter('wash_subscription');
|
||||
self::requireType($subscription, self::type_bool());
|
||||
// Check if the type is a valid type (If it isn't 0)
|
||||
if ((int)$vehicle->type->value() === 0 && $subscription) {
|
||||
// Set the subscription to null
|
||||
$response->error('Unable to set subscription, type is not set', 400);
|
||||
}
|
||||
// Set the wash subscription
|
||||
$vehicle->wash_subscription->set($subscription ? 1 : 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user