- 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.
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
import { PrismaClient } from '@prisma/client';
|
|
|
|
// Initialize Prisma client
|
|
const prisma = new PrismaClient();
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
// Get the form ID from the route params
|
|
const id = event.context.params.id;
|
|
|
|
try {
|
|
// Try to delete by UUID first
|
|
let form;
|
|
try {
|
|
form = await prisma.form.delete({
|
|
where: { formUUID: id }
|
|
});
|
|
} catch (e) {
|
|
// If UUID not found, try numeric ID
|
|
if (!isNaN(parseInt(id))) {
|
|
form = await prisma.form.delete({
|
|
where: { formID: parseInt(id) }
|
|
});
|
|
} else {
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
return {
|
|
success: true,
|
|
message: 'Form deleted successfully'
|
|
};
|
|
} catch (error) {
|
|
console.error(`Error deleting form ${id}:`, error);
|
|
|
|
// Handle specific errors
|
|
if (error.code === 'P2025') {
|
|
return {
|
|
success: false,
|
|
error: 'Form not found'
|
|
};
|
|
}
|
|
|
|
// Handle cases where the form has associated tasks
|
|
if (error.code === 'P2003') {
|
|
return {
|
|
success: false,
|
|
error: 'Cannot delete form because it is associated with one or more tasks'
|
|
};
|
|
}
|
|
|
|
return {
|
|
success: false,
|
|
error: 'Failed to delete form',
|
|
details: process.env.NODE_ENV === 'development' ? error.message : undefined
|
|
};
|
|
}
|
|
});
|