- Updated the form builder to allow users to create new forms with additional fields for category and group, improving organization and usability. - Introduced an empty state in the form builder to guide users in creating new forms. - Enhanced the management page with new filters for category and group, allowing for better form organization and retrieval. - Updated the database schema to include new fields for form category, tags, and group, along with corresponding API adjustments for form creation and updates. - Improved the user interface with better handling of form descriptions and added visual indicators for categories and groups in the forms table.
53 lines
1.6 KiB
JavaScript
53 lines
1.6 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',
|
|
customScript: body.customScript || null,
|
|
customCSS: body.customCSS || null,
|
|
formEvents: body.formEvents || null,
|
|
scriptMode: body.scriptMode || 'safe',
|
|
submitButton: body.submitButton || null,
|
|
formCategory: body.formCategory && body.formCategory.trim() ? body.formCategory.trim() : null,
|
|
formTags: body.formTags || null,
|
|
formGroup: body.formGroup && body.formGroup.trim() ? body.formGroup.trim() : null,
|
|
formCreatedBy: event.context.user?.userID || undefined,
|
|
}
|
|
});
|
|
|
|
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
|
|
};
|
|
}
|
|
});
|