model = new OrderItemModel(); } public function __invoke(ServerRequestInterface $request) { $body = json_decode((string)$request->getBody(), true) ?? []; try { // company_id, order_id e product_id são obrigatórios para criar um item de pedido v::key('company_id', v::intType()->positive()) // company_id agora é obrigatório ->key('order_id', v::intType()->positive()) ->key('product_id', v::intType()->positive()) ->assert($body); } catch (ValidationException $e) { return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(400); } $companyId = (int) $body['company_id']; $orderId = (int) $body['order_id']; $productId = (int) $body['product_id']; $created = $this->model->createOrderItem($orderId, $productId, $companyId); return $created ? ResponseLib::sendOk(['created' => true, 'order_item_id' => $created]) : ResponseLib::sendFail("Failed to create order item", [], "E_DATABASE")->withStatus(500); } }