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.
95 lines
3 KiB
PHP
95 lines
3 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
runAuth();
|
|
|
|
/**
|
|
* Create a task (service bell request or legacy photo task)
|
|
* POST: { BusinessID, TaskTypeID?, ServicePointID?, Message?, ItemID?, TaskType?, Instructions?, PYTReward? }
|
|
*/
|
|
|
|
$data = readJsonBody();
|
|
$businessID = (int) ($data['BusinessID'] ?? 0);
|
|
|
|
if ($businessID <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'BusinessID is required']);
|
|
}
|
|
|
|
try {
|
|
$taskTypeID = (int) ($data['TaskTypeID'] ?? 0);
|
|
|
|
if ($taskTypeID > 0) {
|
|
// Service bell task
|
|
$servicePointID = (int) ($data['ServicePointID'] ?? 0);
|
|
$orderID = (int) ($data['OrderID'] ?? 0);
|
|
$userID = (int) ($data['UserID'] ?? 0);
|
|
$message = $data['Message'] ?? '';
|
|
|
|
// Get task type name for display
|
|
$taskTypeQuery = queryOne("SELECT Name FROM tt_TaskTypes WHERE ID = ?", [$taskTypeID]);
|
|
|
|
$taskTitle = $message;
|
|
if ($taskTypeQuery && !empty(trim($taskTypeQuery['Name']))) {
|
|
$taskTitle = $taskTypeQuery['Name'];
|
|
}
|
|
|
|
$taskDetails = $message;
|
|
|
|
queryTimed("
|
|
INSERT INTO Tasks (
|
|
BusinessID, ServicePointID, TaskTypeID, OrderID, UserID,
|
|
Title, Details, CreatedOn, ClaimedByUserID
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), 0)
|
|
", [
|
|
$businessID,
|
|
$servicePointID,
|
|
$taskTypeID,
|
|
$orderID,
|
|
$userID,
|
|
$taskTitle,
|
|
$taskDetails,
|
|
]);
|
|
} else {
|
|
// Legacy photo task
|
|
$itemID = (int) ($data['ItemID'] ?? 0);
|
|
$taskType = $data['TaskType'] ?? 'employee_photo';
|
|
$instructions = $data['Instructions'] ?? '';
|
|
$pytReward = (int) ($data['PYTReward'] ?? 0);
|
|
|
|
// Get item info if itemID provided
|
|
$itemName = '';
|
|
if ($itemID > 0) {
|
|
$itemQuery = queryOne("SELECT Name FROM Items WHERE ID = ?", [$itemID]);
|
|
if ($itemQuery) $itemName = $itemQuery['Name'];
|
|
}
|
|
|
|
// Create task description
|
|
switch ($taskType) {
|
|
case 'employee_photo':
|
|
$taskDescription = "Take a photo of: $itemName";
|
|
break;
|
|
case 'user_photo':
|
|
$taskDescription = "Submit a photo of $itemName to earn $pytReward PYT";
|
|
break;
|
|
default:
|
|
$taskDescription = $instructions;
|
|
}
|
|
|
|
queryTimed("
|
|
INSERT INTO Tasks (
|
|
BusinessID, TaskItemID, TaskType, TaskDescription,
|
|
TaskInstructions, TaskPYTReward, TaskStatus, CreatedOn
|
|
) VALUES (?, ?, ?, ?, ?, ?, 'pending', NOW())
|
|
", [$businessID, $itemID, $taskType, $taskDescription, $instructions, $pytReward]);
|
|
}
|
|
|
|
$taskID = lastInsertId();
|
|
|
|
jsonResponse([
|
|
'OK' => true,
|
|
'TASK_ID' => (int) $taskID,
|
|
'MESSAGE' => 'Task created successfully',
|
|
]);
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse(['OK' => false, 'ERROR' => $e->getMessage(), 'DETAIL' => '']);
|
|
}
|