added API endpoint to fetch clients assigned to the authenticated coach

This commit is contained in:
2026-05-13 07:36:01 +02:00
parent 81a8bfd906
commit 72cfe274e1
2 changed files with 477 additions and 1 deletions

View File

@ -4,6 +4,7 @@
* GET (no params) -> ordered questionnaire list with conditions
* GET ?id=<questionnaireID> -> single questionnaire in app JSON format
* GET ?translations=1 -> all translations merged across all tables
* GET ?clients=1 -> list of clients assigned to the authenticated coach
* POST -> submit interview answers for a client (coach / supervisor / admin)
*/
@ -158,8 +159,27 @@ if ($method !== 'GET') {
[$pdo, $tmpDb, $lockFp] = qdb_open(false);
$qnID = $_GET['id'] ?? '';
$qnID = $_GET['id'] ?? '';
$translations = $_GET['translations'] ?? '';
$fetchClients = $_GET['clients'] ?? '';
if ($fetchClients) {
require_role(['coach'], $tokenRec);
$coachID = $tokenRec['entityID'] ?? '';
$stmt = $pdo->prepare("
SELECT clientCode
FROM client
WHERE coachID = :cid
ORDER BY clientCode
");
$stmt->execute([':cid' => $coachID]);
$clients = $stmt->fetchAll(PDO::FETCH_COLUMN);
qdb_discard($tmpDb, $lockFp);
json_success(['coachID' => $coachID, 'clients' => $clients]);
}
if ($translations) {
$result = [];