Вопрос закрыт, незнакомый иностранный товарищ помог.
/**
* Listing all tasks of particual user
* method GET
* url /tasks
*/
$app->get('/tasks', 'authenticate', function() {
global $user_id;
$response = array();
$db = new DbHandler();
// fetching all user tasks
$result = $db->getAllUserTasks($user_id);
if ($result != NULL) {
$items = array();
foreach ($result as $rez) {
$response["error"] = false;
$response["id"] = $rez["id"];
$response["task"] = $rez["task"];
$response["status"] = $rez["status"];
$response["createdAt"] = $rez["created_at"];
$items[] = $response;
}
echoRespnse(200, $items);
} else {
$response["error"] = true;
$response["message"] = "The requested resource doesn't exists";
echoRespnse(404, $response);
}
});
/**
* Fetching all user tasks
* @param String $user_id id of the user
*/
public function getAllUserTasks($user_id) {
$stmt = $this->conn->prepare("SELECT t.* FROM tasks t, user_tasks ut WHERE t.id = ut.task_id AND ut.user_id = ?");
$stmt->bind_param("i", $user_id);
if ($stmt->execute()) {
$items = $res = array();
$stmt->bind_result($id, $task, $status, $created_at);
while ($stmt->fetch()) {
$res["id"] = $id;
$res["task"] = $task;
$res["status"] = $status;
$res["created_at"] = $created_at;
$items[] = $res;
}
$stmt->close();
return $items;
} else {
return NULL;
}
}