reverse client reset functionality
Some checks failed
PHPUnit / test (push) Has been cancelled

This commit is contained in:
2026-07-09 16:39:00 +02:00
parent f04388e0ec
commit 351af170a0
4 changed files with 2 additions and 122 deletions

View File

@ -64,43 +64,6 @@ case 'GET':
case 'POST':
$body = read_json_body();
if (($body['action'] ?? '') === 'reset') {
$clientCode = trim((string)($body['clientCode'] ?? ''));
if ($clientCode === '') {
json_error('MISSING_FIELDS', 'clientCode is required', 400);
}
try {
[$pdo, $tmpDb, $lockFp] = qdb_open_write_or_fail();
[$clause, $params] = rbac_client_filter($tokenRec, 'cl', 'all');
$chk = $pdo->prepare(
"SELECT clientCode FROM client cl WHERE cl.clientCode = :cc AND ($clause)"
);
$chk->execute(array_merge([':cc' => $clientCode], $params));
if (!$chk->fetch()) {
qdb_discard($tmpDb, $lockFp);
json_error('NOT_FOUND', 'Client not found or not authorized', 404);
}
require_once __DIR__ . '/../lib/submissions.php';
$pdo->beginTransaction();
$cleared = qdb_delete_client_response_data($pdo, [$clientCode]);
$pdo->commit();
qdb_save($tmpDb, $lockFp);
json_success([
'clientCode' => $clientCode,
'reset' => true,
'cleared' => $cleared,
]);
} catch (Throwable $e) {
qdb_handler_fail($e, 'clients', $pdo ?? null, $tmpDb ?? null, $lockFp ?? null);
}
break;
}
$coachID = trim($body['coachID'] ?? '');
$bulk = !empty($body['bulk']);