@vizioz/teamwork-mcp
Version:
MCP server to connect to the Teamwork.com API
40 lines (39 loc) • 1.24 kB
JavaScript
/**
* updateTask service
* Updates an existing task in Teamwork
*
* PATCH /tasks/{taskId}.json
* The request body should be a TaskRequest object with a task property
*/
import logger from '../../utils/logger.js';
import { ensureApiClient } from '../core/apiClient.js';
/**
* Updates an existing task in Teamwork
* @param taskId The ID of the task to update
* @param taskData The updated task data
* @returns The updated task
*/
export async function updateTask(taskId, taskData) {
try {
const apiClient = await ensureApiClient();
const url = `/tasks/${taskId}.json`;
// Make the PATCH request to update the task
const response = await apiClient.patch(url, taskData);
if (response.status === 200) {
if (response.data.task.name) {
return `Task '${response.data.task.name}' updated successfully`;
}
else {
return `Task updated successfully`;
}
}
else {
throw new Error(response.data.message.status);
}
}
catch (error) {
logger.error(`Error updating task ${taskId}: ${error.message}`);
throw new Error(error.message);
}
}
export default updateTask;