/
npronnikov
/
ProcessVisualizer
Обзор
Документация
Войти
/
npronnikov
/
ProcessVisualizer
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
frontend/src/services/api.ts
140 строк
5 KB
Madnick
Refactor process metrics UI and add process base history workflow
18 май 2026, 17:55
18 май 2026, 17:55
381b9ec
Код
Авторство
О чём код?
import axios from 'axios'; import type { GroupWithMetrics, ProcessWithMetrics, Operation, OperationHistory, CreateGroupDto, UpdateGroupDto, CreateProcessDto, UpdateProcessDto, UpdateOperationDto, ProcessBaseHistory, UpsertProcessBaseHistoryDto, User, LoginDto, CreateUserDto, UpdateUserDto, AttentionZonesSummary, DateComparisonReport, } from '../types'; const api = axios.create({ baseURL: '/api', headers: { 'Content-Type': 'application/json', }, }); // Set user ID for requests that need creator tracking export const setApiUserId = (userId: string | undefined) => { if (userId) { api.defaults.headers.common['x-user-id'] = userId; } else { delete api.defaults.headers.common['x-user-id']; } }; // Groups API export const groupsApi = { getAll: () => api.get<GroupWithMetrics[]>('/groups'), getById: (id: string) => api.get<GroupWithMetrics>(`/groups/${id}`), create: (data: CreateGroupDto) => api.post<GroupWithMetrics>('/groups', data), update: (id: string, data: UpdateGroupDto) => api.put<GroupWithMetrics>(`/groups/${id}`, data), delete: (id: string) => api.delete(`/groups/${id}`), getProcesses: (groupId: string) => api.get<ProcessWithMetrics[]>(`/groups/${groupId}/processes`), }; // Processes API export const processesApi = { getById: (id: string) => api.get<ProcessWithMetrics>(`/processes/${id}`), getProcessAtDate: (id: string, date: string) => api.get<ProcessWithMetrics>(`/processes/${id}`, { params: { date }, }), create: (data: CreateProcessDto) => api.post<ProcessWithMetrics>('/processes', data), update: (id: string, data: UpdateProcessDto) => api.put<ProcessWithMetrics>(`/processes/${id}`, data), updateTargetValue: (id: string, targetValue: number | null) => api.put<ProcessWithMetrics>(`/processes/${id}/target-value`, { targetValue }), delete: (id: string) => api.delete(`/processes/${id}`), uploadBpmn: (id: string, file: File) => { const formData = new FormData(); formData.append('bpmn', file); return api.post<ProcessWithMetrics>(`/processes/${id}/upload-bpmn`, formData, { headers: { 'Content-Type': 'multipart/form-data', }, }); }, getBpmn: (id: string) => api.get(`/processes/${id}/bpmn`, { responseType: 'text', }), getOperations: (id: string, missingOnly?: boolean) => api.get<Operation[]>(`/processes/${id}/operations`, { params: { missingOnly }, }), getOperationsAtDate: (id: string, date: string) => api.get<Operation[]>(`/processes/${id}/operations/at-date`, { params: { date }, }), getBaseHistory: (id: string) => api.get<ProcessBaseHistory[]>(`/processes/${id}/base-history`), createBaseHistory: (id: string, data: UpsertProcessBaseHistoryDto) => api.post<ProcessBaseHistory>(`/processes/${id}/base-history`, data), updateBaseHistory: (id: string, historyId: string, data: UpsertProcessBaseHistoryDto) => api.put<ProcessBaseHistory>(`/processes/${id}/base-history/${historyId}`, data), deleteBaseHistory: (id: string, historyId: string) => api.delete(`/processes/${id}/base-history/${historyId}`), }; // Operations API export const operationsApi = { update: (processId: string, bpmnElementId: string, data: UpdateOperationDto) => api.put<Operation>(`/processes/${processId}/operations/${encodeURIComponent(bpmnElementId)}`, data), delete: (processId: string, bpmnElementId: string) => { const encodedBpmnElementId = encodeURIComponent(bpmnElementId); return api.delete(`/processes/${processId}/operations?bpmnElementId=${encodedBpmnElementId}`); }, createHistory: (processId: string, bpmnElementId: string, data: UpdateOperationDto & { date?: string; operationId?: string }) => api.post<OperationHistory>(`/processes/${processId}/operations/${encodeURIComponent(bpmnElementId)}/history`, data), updateHistory: ( processId: string, bpmnElementId: string, historyId: string, data: UpdateOperationDto & { date?: string; operationId?: string } ) => api.put<OperationHistory>( `/processes/${processId}/operations/${encodeURIComponent(bpmnElementId)}/history/${historyId}`, data ), deleteHistory: (processId: string, bpmnElementId: string, historyId: string) => api.delete(`/processes/${processId}/operations/${encodeURIComponent(bpmnElementId)}/history/${historyId}`), getHistory: (processId: string, bpmnElementId: string) => api.get<OperationHistory[]>(`/processes/${processId}/operations/${encodeURIComponent(bpmnElementId)}/history`), }; // Auth API export const authApi = { login: (data: LoginDto) => api.post<User>('/auth/login', data), getUser: (login: string) => api.get<User>(`/auth/user/${login}`), }; // Users API export const usersApi = { getAll: () => api.get<User[]>('/users'), getById: (id: string) => api.get<User>(`/users/${id}`), create: (data: CreateUserDto) => api.post<User>('/users', data), update: (id: string, data: UpdateUserDto) => api.put<User>(`/users/${id}`, data), delete: (id: string) => api.delete(`/users/${id}`), }; // Analytics API export const analyticsApi = { getAttentionZones: () => api.get<AttentionZonesSummary>('/analytics/attention-zones'), getDateComparison: (date1: string, date2: string) => api.get<DateComparisonReport>('/analytics/date-comparison', { params: { date1, date2 }, }), }; export default api;