Md Afiq Iskandar bb5e4c0637 Add Form and Process Management Features
- Introduced new components for form selection and gateway condition management within the process builder.
- Implemented a `FormSelector` component for selecting and managing forms, including search functionality and loading states.
- Developed a `GatewayConditionManager` component to manage conditions for gateways, allowing users to define and edit conditions visually.
- Created a `ProcessBuilderComponents` component to facilitate the addition of core components in the process builder.
- Enhanced the `ProcessFlowCanvas` to support new features, including edge selection and improved node management.
- Updated the backend API to handle CRUD operations for forms and processes, including error handling for associated tasks.
- Integrated new database models for forms and processes in Prisma, ensuring proper relationships and data integrity.
- Improved state management in the form builder store to accommodate new features and enhance user experience.
2025-05-15 10:27:55 +08:00

85 lines
2.0 KiB
JavaScript

import { PrismaClient } from '@prisma/client';
// Initialize Prisma client
const prisma = new PrismaClient();
export default defineEventHandler(async (event) => {
// Get the process ID from the route params
const id = event.context.params.id;
try {
// Parse the request body
const body = await readBody(event);
// Validate required fields
if (!body.processName) {
return {
success: false,
error: 'Process name is required'
};
}
// Prepare update data
const updateData = {
processName: body.processName,
processModifiedDate: new Date()
};
// Add optional fields if provided
if (body.processDescription !== undefined) {
updateData.processDescription = body.processDescription;
}
if (body.definition !== undefined) {
updateData.processDefinition = body.definition;
}
if (body.processStatus !== undefined) {
updateData.processStatus = body.processStatus;
}
if (body.processVersion !== undefined) {
updateData.processVersion = body.processVersion;
}
// Try to update by UUID first
let process;
try {
process = await prisma.process.update({
where: { processUUID: id },
data: updateData
});
} catch (e) {
// If UUID not found, try numeric ID
if (!isNaN(parseInt(id))) {
process = await prisma.process.update({
where: { processID: parseInt(id) },
data: updateData
});
} else {
throw e;
}
}
return {
success: true,
process
};
} catch (error) {
console.error(`Error updating process ${id}:`, error);
// Handle specific 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
};
}
});