sozsoft-platform/ui/src/services/workflow.service.ts
2026-10-10 23:11:12 +03:00

149 lines
3.5 KiB
TypeScript

import apiService from './api.service'
import type { WorkflowRejectReasonDto } from '@/proxy/form/models'
export type { WorkflowRejectReasonDto }
export interface WorkflowConditionDto {
compareColumn: string
compareOperator: string
compareValue: number
}
export interface CompareOutcomeDto {
label: string
targetId?: string | null
conditions: WorkflowConditionDto[]
}
export interface WorkflowRejectReasonItemDto {
id: string
text: string
}
export interface WorkflowCriteriaDto {
id: string
listFormCode: string
nodeId: string
kind: string
title: string
compareColumn: string
compareOperator: string
compareValue: number
approver: string
nextOnStart?: string | null
nextOnTrue?: string | null
nextOnFalse?: string | null
nextOnApprove?: string | null
nextOnReject?: string | null
positionX: number
positionY: number
compareOutcomes: CompareOutcomeDto[]
rejectReason?: WorkflowRejectReasonDto | null
}
export interface WorkflowCriteriasDto {
criteria: WorkflowCriteriaDto[]
}
export interface WorkflowRunResultDto {
keys: unknown[]
currentNodeId?: string | null
currentNodeTitle?: string | null
currentNodeKind?: string | null
waitingApproval: boolean
completed: boolean
toastMessages?: string[]
}
export type SaveCriteriaInput = Omit<Partial<WorkflowCriteriaDto>, 'id'> & {
id?: string | null
listFormCode: string
}
const baseUrl = '/api/app/list-form-workflow'
export const workflowService = {
async getCriteria(listFormCode?: string) {
const response = await apiService.fetchData<WorkflowCriteriasDto>({
method: 'GET',
url: `${baseUrl}/criteria`,
params: { listFormCode },
})
return response.data
},
async saveCriteria(payload: SaveCriteriaInput) {
const response = await apiService.fetchData<WorkflowCriteriaDto>({
method: 'POST',
url: `${baseUrl}/criteria`,
data: payload,
})
return response.data
},
async deleteCriteria(id: string) {
await apiService.fetchData<void>({
method: 'DELETE',
url: `${baseUrl}/criteria/${id}`,
})
},
async resetDemo(listFormCode?: string) {
const response = await apiService.fetchData<WorkflowCriteriasDto>({
method: 'POST',
url: `${baseUrl}/reset-demo`,
params: { listFormCode },
})
return response.data
},
async startWorkflow(listFormCode: string, keys: unknown[]) {
const response = await apiService.fetchData<WorkflowRunResultDto>({
method: 'POST',
url: `${baseUrl}/start`,
data: { listFormCode, keys },
})
return response.data
},
async resetWorkflow(listFormCode: string, keys: unknown[]) {
const response = await apiService.fetchData<WorkflowRunResultDto>({
method: 'POST',
url: `${baseUrl}/reset`,
data: { listFormCode, keys },
})
return response.data
},
async decideWorkflow(
listFormCode: string,
keys: unknown[],
approved: boolean,
note?: string,
currentNodeId?: string,
rejectReasonId?: string,
) {
const response = await apiService.fetchData<WorkflowRunResultDto>({
method: 'POST',
url: `${baseUrl}/decision`,
data: { listFormCode, keys, approved, note, currentNodeId, rejectReasonId },
})
return response.data
},
async getRejectReasons(listFormCode: string, criteriaId: string) {
const response = await apiService.fetchData<WorkflowRejectReasonItemDto[]>({
method: 'GET',
url: `${baseUrl}/reject-reasons`,
params: { listFormCode, criteriaId },
})
return response.data
},
}