corrad-bp/server/api/forms/create.post.js
Afiq 9ea4e18672 Add Info Display Component and Enhance Form Settings
- Introduced a new 'Info Display' component for displaying read-only information in a key-value format, with customizable layouts and styles.
- Removed the 'Repeater' and 'Group' components from the available components list to streamline options.
- Enhanced the Form Builder configuration to support custom scripts, CSS, and event handling, allowing for more dynamic form behavior.
- Added a modal for Form Settings, enabling users to manage form properties, custom scripts, and event triggers effectively.
- Updated the database schema to accommodate new fields for custom scripts, CSS, and event configurations.
2025-05-26 16:47:53 +08:00

49 lines
1.3 KiB
JavaScript

import { PrismaClient } from '@prisma/client';
import { v4 as uuidv4 } from 'uuid';
// Initialize Prisma client
const prisma = new PrismaClient();
export default defineEventHandler(async (event) => {
try {
// Parse the request body
const body = await readBody(event);
// Validate required fields
if (!body.formName) {
return {
success: false,
error: 'Form name is required'
};
}
// Create a new form in the database
const form = await prisma.form.create({
data: {
formUUID: uuidv4(),
formName: body.formName,
formDescription: body.formDescription || null,
formComponents: body.components || [],
formStatus: body.status || 'active',
formCreatedBy: body.createdBy || null, // In a real app, this would come from the authenticated user
customScript: body.customScript || null,
customCSS: body.customCSS || null,
formEvents: body.formEvents || null,
scriptMode: body.scriptMode || 'safe'
}
});
return {
success: true,
form
};
} catch (error) {
console.error('Error creating form:', error);
return {
success: false,
error: 'Failed to create form',
details: process.env.NODE_ENV === 'development' ? error.message : undefined
};
}
});