2026-02-01 17:28:37 +00:00
|
|
|
// Task service for fetching task status
|
|
|
|
|
|
|
|
|
|
import type { User } from 'oidc-client-ts';
|
|
|
|
|
import type { TaskStatusResponse } from '@/types';
|
|
|
|
|
import { apiRequest } from './apiClient';
|
|
|
|
|
import { API_ENDPOINTS } from '@/constants';
|
|
|
|
|
|
|
|
|
|
export interface CancelTaskResponse {
|
|
|
|
|
success: boolean;
|
|
|
|
|
message: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-01 20:40:07 +00:00
|
|
|
export interface ClearAllTasksResponse {
|
|
|
|
|
success: boolean;
|
|
|
|
|
count: number;
|
|
|
|
|
message: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-01 17:28:37 +00:00
|
|
|
/**
|
|
|
|
|
* Fetch all active tasks for the current user
|
|
|
|
|
*/
|
|
|
|
|
export async function fetchTasksForUser(user: User): Promise<string[]> {
|
|
|
|
|
return apiRequest<string[]>(user, API_ENDPOINTS.TASKS_FOR_USER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch the status of a specific task
|
|
|
|
|
*/
|
|
|
|
|
export async function fetchTaskStatus(
|
|
|
|
|
user: User,
|
|
|
|
|
taskId: string
|
|
|
|
|
): Promise<TaskStatusResponse> {
|
|
|
|
|
return apiRequest<TaskStatusResponse>(user, API_ENDPOINTS.TASK_STATUS, {
|
|
|
|
|
params: { task_id: taskId },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Cancel a running task
|
|
|
|
|
*/
|
|
|
|
|
export async function cancelTask(
|
|
|
|
|
user: User,
|
|
|
|
|
taskId: string
|
|
|
|
|
): Promise<CancelTaskResponse> {
|
|
|
|
|
return apiRequest<CancelTaskResponse>(user, API_ENDPOINTS.CANCEL_TASK, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
params: { task_id: taskId },
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-02-01 20:40:07 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clear all tasks for the current user
|
|
|
|
|
*/
|
|
|
|
|
export async function clearAllTasks(user: User): Promise<ClearAllTasksResponse> {
|
|
|
|
|
return apiRequest<ClearAllTasksResponse>(user, API_ENDPOINTS.CLEAR_ALL_TASKS, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
});
|
|
|
|
|
}
|