| @@ 128-145 (lines=18) @@ | ||
| 125 | * @return array |
|
| 126 | * @throws \Exception |
|
| 127 | */ |
|
| 128 | public function updateTask($input, $taskId) |
|
| 129 | { |
|
| 130 | $task = $this->checkTask($taskId); |
|
| 131 | if (empty($input['task']) && empty($input['status'])) { |
|
| 132 | throw new \Exception(self::TASK_INFO_REQUIRED, 400); |
|
| 133 | } |
|
| 134 | $taskname = isset($input['task']) ? $input['task'] : $task->task; |
|
| 135 | $status = isset($input['status']) ? $input['status'] : $task->status; |
|
| 136 | $repository = new TasksRepository; |
|
| 137 | $query = $repository->updateTaskQuery(); |
|
| 138 | $statement = $this->database->prepare($query); |
|
| 139 | $statement->bindParam('id', $taskId); |
|
| 140 | $statement->bindParam('task', $taskname); |
|
| 141 | $statement->bindParam('status', $status); |
|
| 142 | $statement->execute(); |
|
| 143 | ||
| 144 | return $this->checkTask($taskId); |
|
| 145 | } |
|
| 146 | ||
| 147 | /** |
|
| 148 | * Delete a task. |
|
| @@ 136-156 (lines=21) @@ | ||
| 133 | * @return array |
|
| 134 | * @throws \Exception |
|
| 135 | */ |
|
| 136 | public function updateUser($input, $userId) |
|
| 137 | { |
|
| 138 | $user = $this->checkUser($userId); |
|
| 139 | if (empty($input['name']) && empty($input['email'])) { |
|
| 140 | throw new \Exception(self::USER_INFO_REQUIRED, 400); |
|
| 141 | } |
|
| 142 | $username = isset($input['name']) ? $input['name'] : $user->name; |
|
| 143 | $email = $user->email; |
|
| 144 | if (isset($input['email'])) { |
|
| 145 | $email = $this->validateEmail($input['email']); |
|
| 146 | } |
|
| 147 | $repository = new UsersRepository; |
|
| 148 | $query = $repository->updateUserQuery(); |
|
| 149 | $statement = $this->database->prepare($query); |
|
| 150 | $statement->bindParam('id', $userId); |
|
| 151 | $statement->bindParam('name', $username); |
|
| 152 | $statement->bindParam('email', $email); |
|
| 153 | $statement->execute(); |
|
| 154 | ||
| 155 | return $this->checkUser($userId); |
|
| 156 | } |
|
| 157 | ||
| 158 | /** |
|
| 159 | * Delete a user. |
|