40 lines
1.8 KiB
TypeScript
40 lines
1.8 KiB
TypeScript
import { api } from './http'
|
|
import type { WorkflowDefinition, WorkflowExecutionDetail, WorkflowExecutionRecord, WorkflowExecutionResult } from '@/types/workflow'
|
|
|
|
export const workflowApi = {
|
|
create: async (wf: WorkflowDefinition): Promise<WorkflowDefinition> => {
|
|
const res = await api.post('/api/workflows', wf)
|
|
return res.data
|
|
},
|
|
update: async (id: string, wf: WorkflowDefinition): Promise<WorkflowDefinition> => {
|
|
const res = await api.put(`/api/workflows/${id}`, wf)
|
|
return res.data
|
|
},
|
|
save: async (wf: WorkflowDefinition): Promise<WorkflowDefinition> => {
|
|
return wf.id ? workflowApi.update(wf.id, wf) : workflowApi.create(wf)
|
|
},
|
|
getById: async (id: string): Promise<WorkflowDefinition> => {
|
|
const res = await api.get(`/api/workflows/${id}`)
|
|
return res.data
|
|
},
|
|
list: async (status?: string, page = 1, size = 10): Promise<{ items: WorkflowDefinition[]; page: number; size: number; total: number }> => {
|
|
const res = await api.get('/api/workflows', { params: { status, page, size } })
|
|
return res.data
|
|
},
|
|
remove: async (id: string): Promise<void> => {
|
|
await api.delete(`/api/workflows/${id}`)
|
|
},
|
|
execute: async (id: string, input: Record<string, any>): Promise<WorkflowExecutionResult> => {
|
|
const res = await api.post(`/api/workflows/${id}/execute`, { input })
|
|
return res.data
|
|
},
|
|
getExecutions: async (id: string, page = 1, size = 10): Promise<{ items: WorkflowExecutionRecord[]; page: number; size: number; total: number }> => {
|
|
const res = await api.get(`/api/workflows/${id}/executions`, { params: { page, size } })
|
|
return res.data
|
|
},
|
|
getExecutionDetail: async (executionId: string): Promise<WorkflowExecutionDetail> => {
|
|
const res = await api.get(`/api/workflows/executions/${executionId}`)
|
|
return res.data
|
|
},
|
|
}
|