- Implemented complete API system with REST endpoints for all process operations, including CRUD functionality. - Added support for direct process linking via URL parameters, improving navigation and usability. - Enhanced save functionality with success/error notifications and improved state management. - Fixed navigation issues, including unsaved changes detection and automatic URL synchronization. - Resolved Vue Flow interference, allowing for seamless connector dragging between nodes. - Ensured backward compatibility for legacy process definitions, automatically upgrading them. - Introduced comprehensive toast notifications for user feedback on all operations. - Optimized performance by reducing re-renders and improving memory management. - Enhanced error handling with robust validation and graceful recovery throughout the system. - Updated UI consistency across form builder and process builder management interfaces.
114 lines
3.5 KiB
JavaScript
114 lines
3.5 KiB
JavaScript
import { PrismaClient } from '@prisma/client';
|
|
import { defineEventHandler, getRouterParam, readBody } from 'h3';
|
|
|
|
// Initialize Prisma client
|
|
const prisma = new PrismaClient();
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
// Get the process ID from the route parameter
|
|
const processId = getRouterParam(event, 'id');
|
|
|
|
if (!processId) {
|
|
return {
|
|
success: false,
|
|
error: 'Process ID is required'
|
|
};
|
|
}
|
|
|
|
// Parse the request body
|
|
const body = await readBody(event);
|
|
|
|
// Check if the ID is a UUID or numeric ID
|
|
const isUUID = processId.length === 36 && processId.includes('-');
|
|
|
|
// Build update data
|
|
const updateData = {};
|
|
|
|
// Basic fields
|
|
if (body.processName !== undefined) updateData.processName = body.processName;
|
|
if (body.processDescription !== undefined) updateData.processDescription = body.processDescription;
|
|
if (body.processCategory !== undefined) updateData.processCategory = body.processCategory;
|
|
if (body.processPriority !== undefined) updateData.processPriority = body.processPriority;
|
|
if (body.processOwner !== undefined) updateData.processOwner = body.processOwner;
|
|
if (body.processStatus !== undefined) updateData.processStatus = body.processStatus;
|
|
if (body.isTemplate !== undefined) updateData.isTemplate = body.isTemplate;
|
|
if (body.templateCategory !== undefined) updateData.templateCategory = body.templateCategory;
|
|
|
|
// Process definition (nodes, edges, viewport)
|
|
if (body.nodes !== undefined || body.edges !== undefined || body.viewport !== undefined) {
|
|
updateData.processDefinition = {
|
|
nodes: body.nodes || [],
|
|
edges: body.edges || [],
|
|
viewport: body.viewport || { x: 0, y: 0, zoom: 1 }
|
|
};
|
|
}
|
|
|
|
// Process variables
|
|
if (body.variables !== undefined) {
|
|
updateData.processVariables = Object.keys(body.variables).length > 0 ? body.variables : null;
|
|
}
|
|
|
|
// Process settings
|
|
if (body.settings !== undefined) {
|
|
updateData.processSettings = Object.keys(body.settings).length > 0 ? body.settings : null;
|
|
}
|
|
|
|
// Process permissions
|
|
if (body.permissions !== undefined) {
|
|
updateData.processPermissions = Object.keys(body.permissions).length > 0 ? body.permissions : null;
|
|
}
|
|
|
|
// Version increment if major changes
|
|
if (body.incrementVersion === true) {
|
|
const currentProcess = await prisma.process.findFirst({
|
|
where: isUUID
|
|
? { processUUID: processId }
|
|
: { processID: parseInt(processId) },
|
|
select: { processVersion: true }
|
|
});
|
|
|
|
if (currentProcess) {
|
|
updateData.processVersion = currentProcess.processVersion + 1;
|
|
}
|
|
}
|
|
|
|
// Update the process
|
|
const updatedProcess = await prisma.process.update({
|
|
where: isUUID
|
|
? { processUUID: processId }
|
|
: { processID: parseInt(processId) },
|
|
data: updateData,
|
|
include: {
|
|
creator: {
|
|
select: {
|
|
userID: true,
|
|
userFullName: true,
|
|
userUsername: true
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
return {
|
|
success: true,
|
|
process: updatedProcess
|
|
};
|
|
} catch (error) {
|
|
console.error('Error updating process:', error);
|
|
|
|
// Handle specific Prisma errors
|
|
if (error.code === 'P2025') {
|
|
return {
|
|
success: false,
|
|
error: 'Process not found'
|
|
};
|
|
}
|
|
|
|
return {
|
|
success: false,
|
|
error: 'Failed to update process',
|
|
details: process.env.NODE_ENV === 'development' ? error.message : undefined
|
|
};
|
|
}
|
|
}); |