100 lines
3.2 KiB
TypeScript
100 lines
3.2 KiB
TypeScript
import apiClient from './client'
|
||
import type { ApprovalFlowNode, ApiResponse } from '@/types/api'
|
||
|
||
export interface CreateFlowNodeRequest {
|
||
category_id: number
|
||
parent_id?: number | null
|
||
key: string
|
||
label: string
|
||
data_key?: string | null
|
||
data_value?: string | null
|
||
is_input?: boolean
|
||
input_key?: string | null
|
||
input_hint?: string | null
|
||
is_multi_select?: boolean
|
||
multi_select_key?: string | null
|
||
multi_select_value?: string | null
|
||
topic_code?: string | null
|
||
message_template?: string | null
|
||
code_template?: string | null
|
||
sort_order?: number
|
||
}
|
||
|
||
export interface UpdateFlowNodeRequest {
|
||
id: number
|
||
category_id?: number
|
||
parent_id?: number | null
|
||
key?: string
|
||
label?: string
|
||
data_key?: string | null
|
||
data_value?: string | null
|
||
is_input?: boolean
|
||
input_key?: string | null
|
||
input_hint?: string | null
|
||
is_multi_select?: boolean
|
||
multi_select_key?: string | null
|
||
multi_select_value?: string | null
|
||
topic_code?: string | null
|
||
message_template?: string | null
|
||
code_template?: string | null
|
||
sort_order?: number
|
||
}
|
||
|
||
export interface MoveFlowNodeRequest {
|
||
new_parent_id?: number | null
|
||
new_sort_order?: number
|
||
}
|
||
|
||
export interface SaveTreeRequest {
|
||
nodes: ApprovalFlowNode[]
|
||
}
|
||
|
||
// Живой предпросмотр: код темы + текст сообщения согласующему для
|
||
// конкретного набора ответов (collected: data_key -> data_value),
|
||
// посчитанные тем же движком, что использует боевой бот.
|
||
export interface PreviewFlowRequest {
|
||
collected: Record<string, string>
|
||
initiator_name?: string
|
||
}
|
||
|
||
export interface PreviewFlowResponse {
|
||
code: string
|
||
message: string
|
||
incomplete: boolean
|
||
topic_exists: boolean
|
||
topic_id?: number
|
||
topic_name?: string
|
||
}
|
||
|
||
export const flowNodesApi = {
|
||
getTree: (categoryId: number) =>
|
||
apiClient.get<ApiResponse<ApprovalFlowNode[]>>(`/flow-nodes/category/${categoryId}?limit=1000`),
|
||
|
||
getById: (id: number) =>
|
||
apiClient.get<ApprovalFlowNode>(`/flow-nodes/${id}`),
|
||
|
||
create: (data: CreateFlowNodeRequest) =>
|
||
apiClient.post<ApprovalFlowNode>('/flow-nodes/', data),
|
||
|
||
update: (data: UpdateFlowNodeRequest) =>
|
||
apiClient.put<ApprovalFlowNode>('/flow-nodes/', data),
|
||
|
||
delete: (id: number) =>
|
||
apiClient.delete<boolean>('/flow-nodes/', { data: { id } }),
|
||
|
||
saveTree: (categoryId: number, data: SaveTreeRequest) =>
|
||
apiClient.post<boolean>(`/flow-nodes/category/${categoryId}/tree`, data),
|
||
|
||
move: (id: number, data: MoveFlowNodeRequest) =>
|
||
apiClient.post<ApprovalFlowNode>(`/flow-nodes/${id}/move`, data),
|
||
|
||
duplicate: (id: number) =>
|
||
apiClient.post<ApprovalFlowNode>(`/flow-nodes/${id}/duplicate`, {}),
|
||
|
||
// НОВОЕ
|
||
preview: (categoryId: number, data: PreviewFlowRequest) =>
|
||
apiClient.post<PreviewFlowResponse>(`/flow-nodes/category/${categoryId}/preview`, data),
|
||
|
||
// НОВОЕ: форсировать обновление Registry в процессе бота (без перезапуска)
|
||
reloadBot: () => apiClient.post<boolean>('/flow-nodes/reload-bot', {}),
|
||
} |