corrad-bp/server/api/forms/[id].put.js
Afiq fa90c234c5 Enhance Process Builder with New Features and Configuration Options
- Added a new ProcessTemplatesModal component for selecting process flow templates, improving user experience in template management.
- Introduced a ProcessSettingsModal component for comprehensive process configuration, including process info, execution settings, and permissions management.
- Updated BusinessRuleNodeConfiguration and FormNodeConfiguration components to enhance user interaction and streamline configuration processes.
- Implemented new API endpoints for managing form fields and settings, allowing for better integration and data handling.
- Enhanced existing components with improved styling and functionality, including dynamic field conditions and bidirectional data mapping.
- Updated nuxt.config.js to include security settings for API routes, ensuring better protection against XSS and request size limitations.
- Removed the deprecated TaskNodeConfiguration component to streamline the process builder interface.
- Improved documentation to reflect recent changes and enhancements in the process builder features.
2025-05-27 17:00:24 +08:00

95 lines
2.2 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 {
// Parse the request body
const body = await readBody(event);
// Validate required fields
if (!body.formName) {
return {
success: false,
error: 'Form name is required'
};
}
// Prepare update data
const updateData = {
formName: body.formName,
formComponents: body.components || [],
formModifiedDate: new Date()
};
// Add optional fields if provided
if (body.formDescription !== undefined) {
updateData.formDescription = body.formDescription;
}
if (body.status !== undefined) {
updateData.formStatus = body.status;
}
// Add the missing custom script and styling fields
if (body.customScript !== undefined) {
updateData.customScript = body.customScript;
}
if (body.customCSS !== undefined) {
updateData.customCSS = body.customCSS;
}
if (body.formEvents !== undefined) {
updateData.formEvents = body.formEvents;
}
if (body.scriptMode !== undefined) {
updateData.scriptMode = body.scriptMode;
}
// Try to update by UUID first
let form;
try {
form = await prisma.form.update({
where: { formUUID: id },
data: updateData
});
} catch (e) {
// If UUID not found, try numeric ID
if (!isNaN(parseInt(id))) {
form = await prisma.form.update({
where: { formID: parseInt(id) },
data: updateData
});
} else {
throw e;
}
}
return {
success: true,
form
};
} catch (error) {
console.error(`Error updating form ${id}:`, error);
// Handle specific errors
if (error.code === 'P2025') {
return {
success: false,
error: 'Form not found'
};
}
return {
success: false,
error: 'Failed to update form',
details: process.env.NODE_ENV === 'development' ? error.message : undefined
};
}
});