44 lines
1 KiB
TypeScript
44 lines
1 KiB
TypeScript
|
|
// 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;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 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 },
|
||
|
|
});
|
||
|
|
}
|