added completion info to client api
This commit is contained in:
@ -176,8 +176,20 @@ Success:
|
||||
"ok": true,
|
||||
"data": {
|
||||
"clients": [
|
||||
"CLIENT-001",
|
||||
"CLIENT-002"
|
||||
{
|
||||
"clientCode": "CLIENT-001",
|
||||
"completedQuestionnaires": [
|
||||
{
|
||||
"questionnaireID": "questionnaire_1_demographic_information",
|
||||
"sumPoints": 42,
|
||||
"completedAt": 1714471800
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"clientCode": "CLIENT-002",
|
||||
"completedQuestionnaires": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@ -185,7 +197,12 @@ Success:
|
||||
|
||||
Fields:
|
||||
|
||||
- `clients`: array of client code strings assigned to the coach, ordered alphabetically.
|
||||
- `clients`: array of client objects assigned to the coach, ordered alphabetically by `clientCode`.
|
||||
- `clients[].clientCode`: the client's code string.
|
||||
- `clients[].completedQuestionnaires`: array of questionnaires already completed by this client. Empty array if none.
|
||||
- `clients[].completedQuestionnaires[].questionnaireID`: the questionnaire ID, matching the IDs from the questionnaire list endpoint.
|
||||
- `clients[].completedQuestionnaires[].sumPoints`: total points from the last upload for this questionnaire.
|
||||
- `clients[].completedQuestionnaires[].completedAt`: Unix timestamp (seconds) of when the questionnaire was completed, or `null` if not recorded.
|
||||
|
||||
Common failures:
|
||||
|
||||
@ -411,7 +428,18 @@ data class SubmitQuestionnaireResponse(
|
||||
)
|
||||
|
||||
data class ClientsResponse(
|
||||
val clients: List<String>
|
||||
val clients: List<ClientInfo>
|
||||
)
|
||||
|
||||
data class ClientInfo(
|
||||
val clientCode: String,
|
||||
val completedQuestionnaires: List<CompletedQuestionnaire> = emptyList()
|
||||
)
|
||||
|
||||
data class CompletedQuestionnaire(
|
||||
val questionnaireID: String,
|
||||
val sumPoints: Int,
|
||||
val completedAt: Long?
|
||||
)
|
||||
```
|
||||
|
||||
|
||||
@ -175,7 +175,32 @@ if ($fetchClients) {
|
||||
ORDER BY clientCode
|
||||
");
|
||||
$stmt->execute([':cid' => $coachID]);
|
||||
$clients = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
$clientCodes = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
$completions = [];
|
||||
if (!empty($clientCodes)) {
|
||||
$placeholders = implode(',', array_fill(0, count($clientCodes), '?'));
|
||||
$stmt2 = $pdo->prepare("
|
||||
SELECT clientCode, questionnaireID, sumPoints, completedAt
|
||||
FROM completed_questionnaire
|
||||
WHERE clientCode IN ($placeholders)
|
||||
");
|
||||
$stmt2->execute($clientCodes);
|
||||
foreach ($stmt2->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
$completions[$row['clientCode']][] = [
|
||||
'questionnaireID' => $row['questionnaireID'],
|
||||
'sumPoints' => (int) $row['sumPoints'],
|
||||
'completedAt' => $row['completedAt'] !== null ? (int) $row['completedAt'] : null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$clients = array_map(function ($code) use ($completions) {
|
||||
return [
|
||||
'clientCode' => $code,
|
||||
'completedQuestionnaires' => $completions[$code] ?? [],
|
||||
];
|
||||
}, $clientCodes);
|
||||
|
||||
qdb_discard($tmpDb, $lockFp);
|
||||
json_success(['coachID' => $coachID, 'clients' => $clients]);
|
||||
|
||||
Reference in New Issue
Block a user