public function find($id) { $order = $this->ordersRepository->find($id); $client = $this->clientsRepository->findBy(['id' => $order->getClientId()])->current(); $ptype = $this->ptypesRepository->findBy(['id' => $order->getPtypeId()])->current(); $user = $this->usersRepository->findBy(['id' => $order->getUserId()])->current(); $sql = $this->ordersRepository->getItemTable()->getSql(); $select = $sql->select(); $select->join('products', 'order_items.product_id = products.id', ['product_name' => 'name'])->where(['order_id' => $order->getId()]); $items = $this->ordersRepository->getItemTable()->selectWith($select); foreach ($items as $item) { $order->addItem($item); } $hydrator = new ClassMethods(); $hydrator->addStrategy('items', new OrdersItemsHydratorStrategy(new ClassMethods())); $order->setClient($hydrator->extract($client)); $order->setPtype($hydrator->extract($ptype)); $order->setUser($hydrator->extract($user)); $result = $hydrator->extract($order); unset($result['client_id']); unset($result['ptype_id']); unset($result['user_id']); unset($result['user']['username']); unset($result['user']['password']); return $result; }
/** * Update a resource * * @param mixed $id * @param mixed $data * @return ApiProblem|mixed */ public function update($id, $data) { if (!$this->userService->isAdmin()) { return new ApiProblem(403, 'Only admin can update clients.'); } return $this->repository->update($id, $data); }
/** * Update a resource * * @param mixed $id * @param mixed $data * @return ApiProblem|mixed */ public function update($id, $data) { $user = $this->userRepository->findByUsername($this->getIdentity()->getRoleId()); if ($user->getRole() != "admin") { return new ApiProblem("403", "The user has not access to this info."); } return $this->repository->update($id, (array) $data); }
/** * Update a resource * * @param mixed $id * @param mixed $data * @return ApiProblem|mixed */ public function update($id, $data) { $userRepository = $this->repository->getUsersRepository(); $user = $userRepository->findByUsername($this->getIdentity()->getRoleId()); if ($user->getRole() == "admin") { return $this->repository->update($id, $data); } return new ApiProblem(403, 'Sem autorização para Editar'); }
/** * Update a resource * * @param mixed $id * @param mixed $data * @return ApiProblem|mixed */ public function update($id, $data) { $usuarioLogado = $this->getUsuarioLogado(); if ($usuarioLogado->getRole() === 'admin') { return $this->repository->update($id, $data); } else { return new ApiProblem(403, "Apenas usuários 'admin' podem editar os produtos"); } }
/** * Update a resource * * @param mixed $id * @param mixed $data * @return ApiProblem|mixed */ public function update($id, $data) { try { $this->authService->hasRole('admin'); return $this->repository->update($id, $data); } catch (\Exception $e) { return new ApiProblem($e->getCode(), $e->getMessage()); } }
public function findByName($name) { return $this->clientsRepository->findByName($name); }