windmill/f/clickup/get_task.deno.ts

32 lines
952 B
TypeScript

import { TaskResponse, ClickupCredentials, ClickUpError } from "/f/types/clickup.deno.ts";
import { filterTaskFields, FieldSelector } from "/f/clickup/utils/filter-task-fields.deno.ts";
export async function main(
task_id: string,
fields: FieldSelector = ["id", "name", "status", "date_created"],
credentials: ClickupCredentials
) {
// Input validation
if (!task_id?.trim()) throw new Error("Task ID is required");
// API call
const response = await fetch(
`https://api.clickup.com/api/v2/task/${task_id}`,
{
headers: {
"Authorization": credentials.access_token,
},
}
);
if (!response.ok) {
const error: ClickUpError = await response.json();
throw new Error(`ClickUp Error ${error.code}: ${error.err}`);
}
// Full response parsing
const fullTask: TaskResponse = await response.json();
// Field filtering
return fields.length > 0 ? filterTaskFields(fullTask, fields) : fullTask;
}