Complete port of all 163 API endpoints from Lucee/CFML to PHP 8.3. Shared helpers in api/helpers.php (DB, auth, request/response, security). PDO prepared statements throughout. Same JSON response shapes as CFML.
38 lines
1.2 KiB
PHP
38 lines
1.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
runAuth();
|
|
|
|
/**
|
|
* Delete a task type for a business
|
|
* POST: { TaskTypeID, BusinessID }
|
|
*/
|
|
|
|
$data = readJsonBody();
|
|
$taskTypeID = (int) ($data['TaskTypeID'] ?? 0);
|
|
$businessID = (int) ($data['BusinessID'] ?? 0);
|
|
|
|
if ($taskTypeID <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'missing_params', 'MESSAGE' => 'TaskTypeID is required']);
|
|
}
|
|
if ($businessID <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'missing_params', 'MESSAGE' => 'BusinessID is required']);
|
|
}
|
|
|
|
try {
|
|
$qCheck = queryOne("SELECT ID, BusinessID FROM tt_TaskTypes WHERE ID = ?", [$taskTypeID]);
|
|
|
|
if (!$qCheck) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'not_found', 'MESSAGE' => 'Task type not found']);
|
|
}
|
|
|
|
if ((int) ($qCheck['BusinessID'] ?? 0) !== $businessID) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'not_authorized', 'MESSAGE' => 'Task type does not belong to this business']);
|
|
}
|
|
|
|
queryTimed("DELETE FROM tt_TaskTypes WHERE ID = ? AND BusinessID = ?", [$taskTypeID, $businessID]);
|
|
|
|
jsonResponse(['OK' => true, 'MESSAGE' => 'Task type deleted']);
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => $e->getMessage()]);
|
|
}
|