conflicts resolved
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is failing

This commit is contained in:
Do-raa
2024-12-20 12:22:35 +01:00
parent b9719e0c98
commit 6d6d70295d
45 changed files with 3200 additions and 1709 deletions

View File

@@ -0,0 +1,49 @@
import prisma from '~/lib/prisma';
import { defineEventHandler, readBody, createError } from 'h3';
export default defineEventHandler(async (event) => {
try {
// Read the request body
const body = await readBody(event);
// Validate the input: Name, Email, and optionally Comment
const { name, email, comment } = body;
if (!name || !email) {
throw createError({
statusCode: 400,
message: 'Name and Email are required',
});
}
// Create the charte entry in the database
const charte = await prisma.charte.create({
data: {
name,
email,
comment: comment || '', // Default to an empty string if no comment is provided
},
});
// Return success and the created charte data
return { success: true, charte };
} catch (error) {
// Log the error for debugging
console.error('Error in charte API:', error);
// Handle specific Prisma or validation errors
if (error.code === 'P2002') {
// Prisma-specific error for unique constraint violations (e.g., unique email)
throw createError({
statusCode: 409,
message: 'A charte entry with this email already exists.',
});
}
// Return a general error for unexpected issues
throw createError({
statusCode: error.statusCode || 500,
message: error.message || 'Internal Server Error',
});
}
});