New endpoints at api/tasks/team/ for centralized bot task tracking: - POST create.php — register a new task - POST update.php — change status, add notes (auto-sets PausedOn/CompletedOn) - GET active.php — list active/paused tasks, optional BotName filter - GET list.php — full listing with filters (BotName, Status, Channel, AssignedBy, Since) and pagination Includes schema.sql for the TeamTasks table. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../../helpers.php';
|
|
|
|
/**
|
|
* POST /api/tasks/team/create.php
|
|
* Register a new team task.
|
|
*
|
|
* Body: { BotName, Title, Channel?, Notes?, AssignedBy? }
|
|
* Returns: { OK: true, ID: <new task ID> }
|
|
*/
|
|
|
|
$data = readJsonBody();
|
|
|
|
$botName = trim($data['BotName'] ?? '');
|
|
$title = trim($data['Title'] ?? '');
|
|
$channel = trim($data['Channel'] ?? '');
|
|
$notes = trim($data['Notes'] ?? '');
|
|
$assignedBy = trim($data['AssignedBy'] ?? '');
|
|
|
|
// Validate required fields
|
|
if ($botName === '' || $title === '') {
|
|
http_response_code(400);
|
|
apiAbort(['OK' => false, 'ERROR' => 'BotName and Title are required']);
|
|
}
|
|
|
|
// Length guards
|
|
if (strlen($botName) > 50) {
|
|
http_response_code(400);
|
|
apiAbort(['OK' => false, 'ERROR' => 'BotName max 50 characters']);
|
|
}
|
|
if (strlen($title) > 255) {
|
|
http_response_code(400);
|
|
apiAbort(['OK' => false, 'ERROR' => 'Title max 255 characters']);
|
|
}
|
|
|
|
try {
|
|
queryTimed("
|
|
INSERT INTO TeamTasks (BotName, Title, Status, Channel, StartedOn, Notes, AssignedBy)
|
|
VALUES (?, ?, 'active', ?, NOW(), ?, ?)
|
|
", [
|
|
$botName,
|
|
$title,
|
|
$channel ?: null,
|
|
$notes ?: null,
|
|
$assignedBy ?: null,
|
|
]);
|
|
|
|
$id = (int) lastInsertId();
|
|
|
|
jsonResponse(['OK' => true, 'ID' => $id]);
|
|
} catch (Throwable $e) {
|
|
http_response_code(500);
|
|
apiAbort(['OK' => false, 'ERROR' => 'Failed to create task: ' . $e->getMessage()]);
|
|
}
|