/** * 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) { try { $this->authService->hasRole(['admin', 'salesman']); if ($this->authService->isAdmin()) { return $this->usersService->update($id, $data); } elseif ((int) $id == $this->authService->getUser()->getId()) { if (isset($data->role)) { unset($data->role); } return $this->usersService->update($id, $data); } return new ApiProblem(401, 'Access denied'); } catch (\Exception $e) { return new ApiProblem($e->getCode(), $e->getMessage()); } }