diff --git a/changelog/62_UNRELEASED_xxxx-xx-xx.md b/changelog/62_UNRELEASED_xxxx-xx-xx.md index ae701289..d4da186d 100644 --- a/changelog/62_UNRELEASED_xxxx-xx-xx.md +++ b/changelog/62_UNRELEASED_xxxx-xx-xx.md @@ -75,6 +75,8 @@ ### API improvements/fixes - Added a new API endpoint `/system/localization-strings` to get the localization strings (gettext JSON representation; in the by the user desired language) +- The `GET /chores` endpoint now also returns the `next_execution_assigned_user` per chore (like the endpoint `GET /chores​/{choreId}` already did for a single chore) +- The `GET /tasks` endpoint now also returns the assigned user and category object per task - Fixed that due soon products with `due_type` = "Expiration date" were missing in `due_products` of the `/stock/volatile` endpoint - Fixed that `PUT/DELETE /objects/{entity}/{objectId}` produced an internal server error when the given object id was invalid (now returns `400 Bad Request`) - Fixed that hyphens in filter values did not work diff --git a/services/ChoresService.php b/services/ChoresService.php index 61c9e7c5..7f7da859 100644 --- a/services/ChoresService.php +++ b/services/ChoresService.php @@ -140,7 +140,22 @@ class ChoresService extends BaseService public function GetCurrent() { - return $this->getDatabase()->chores_current(); + $users = $this->getUsersService()->GetUsersAsDto(); + + $chores = $this->getDatabase()->chores_current(); + foreach ($chores as $chore) + { + if (!empty($chore->next_execution_assigned_to_user_id)) + { + $chore->next_execution_assigned_user = FindObjectInArrayByPropertyValue($users, 'id', $chore->next_execution_assigned_to_user_id); + } + else + { + $chore->next_execution_assigned_user = null; + } + } + + return $chores; } public function TrackChore(int $choreId, string $trackedTime, $doneBy = GROCY_USER_ID) diff --git a/services/TasksService.php b/services/TasksService.php index 99eec7f5..9bbcf34b 100644 --- a/services/TasksService.php +++ b/services/TasksService.php @@ -6,7 +6,32 @@ class TasksService extends BaseService { public function GetCurrent(): \LessQL\Result { - return $this->getDatabase()->tasks_current(); + $users = $this->getUsersService()->GetUsersAsDto(); + $categories = $this->getDatabase()->task_categories(); + + $tasks = $this->getDatabase()->tasks_current(); + foreach ($tasks as $task) + { + if (!empty($task->assigned_to_user_id)) + { + $task->assigned_to_user = FindObjectInArrayByPropertyValue($users, 'id', $task->assigned_to_user_id); + } + else + { + $task->assigned_to_user = null; + } + + if (!empty($task->category_id)) + { + $task->category = FindObjectInArrayByPropertyValue($categories, 'id', $task->category_id); + } + else + { + $task->category = null; + } + } + + return $tasks; } public function MarkTaskAsCompleted($taskId, $doneTime)