|
|
@@ -31,11 +31,9 @@ class OrderCreateController
|
|
|
->key('order_name', v::stringType()->notEmpty()->alnum(' '))
|
|
|
->key('order_phone', v::optional(v::stringType()->notEmpty()->length(8, 20)), false)
|
|
|
->key('status_status', v::stringType()->notEmpty()->in(['Aberta', 'Finalizada', 'Cancelada']))
|
|
|
- ->key('kitchen_note', v::optional(v::stringType()), false)
|
|
|
->assert($body);
|
|
|
} catch (ValidationException $e) {
|
|
|
- return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")
|
|
|
- ->withStatus(400);
|
|
|
+ return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(400);
|
|
|
}
|
|
|
|
|
|
$tableId = (int) $body['table_id'];
|
|
|
@@ -44,20 +42,18 @@ class OrderCreateController
|
|
|
$orderPhone = $body['order_phone'] ?? '';
|
|
|
$statusStatus = $body['status_status'];
|
|
|
$userName = $body['user_name'];
|
|
|
- $kitchenNote = isset($body['kitchen_note']) ? trim($body['kitchen_note']) : '';
|
|
|
|
|
|
// Buscar user_id correspondente ao user_name
|
|
|
$userId = $this->getUserIdByUserName($userName, $companyId);
|
|
|
+
|
|
|
if (!$userId) {
|
|
|
- return ResponseLib::sendFail("Usuário '{$userName}' não encontrado", [], "E_USER_NOT_FOUND")
|
|
|
- ->withStatus(404);
|
|
|
+ return ResponseLib::sendFail("Usuário '{$userName}' não encontrado", [], "E_USER_NOT_FOUND")->withStatus(404);
|
|
|
}
|
|
|
|
|
|
- // Buscar status_id correspondente ao status_status
|
|
|
$statusId = $this->model->getStatusIdByName($statusStatus);
|
|
|
+
|
|
|
if ($statusId === null) {
|
|
|
- return ResponseLib::sendFail("Invalid status_status provided: '{$statusStatus}'", [], "E_VALIDATE")
|
|
|
- ->withStatus(400);
|
|
|
+ return ResponseLib::sendFail("Invalid status_status provided: '{$statusStatus}'", [], "E_VALIDATE")->withStatus(400);
|
|
|
}
|
|
|
|
|
|
$created = $this->model->createOrder(
|
|
|
@@ -66,8 +62,7 @@ class OrderCreateController
|
|
|
$companyId,
|
|
|
$orderName,
|
|
|
$orderPhone,
|
|
|
- $statusId,
|
|
|
- $kitchenNote
|
|
|
+ $statusId
|
|
|
);
|
|
|
|
|
|
return $created
|
|
|
@@ -85,4 +80,4 @@ class OrderCreateController
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
-}
|
|
|
+}
|