Skip to content

Commit

Permalink
create form fixes remove slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
nizzyabi committed Feb 7, 2025
1 parent f867dc3 commit 5650e53
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions apps/web/pages/api/templates/create-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,27 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}

// Find the template either by ID or slug
const templateForm = routingForms.find((form: any) =>
const templateForm = routingForms.find((form) =>
templateId ? form.id === templateId : slugify(form.name) === slug
);

if (!templateForm) {
return res.status(404).json({ message: "Template not found" });
}

// Validate template data before creating
if (!templateForm.template || !templateForm.name) {
return res.status(400).json({ message: "Invalid template data" });
}

const newForm = await prisma.app_RoutingForms_Form.create({
data: {
name: `${templateForm.name}`,
name: templateForm.name,
description: templateForm.description || "",
disabled: false,
userId: session.user.id,
fields: Array.isArray(templateForm.template.fields) ? templateForm.template.fields : [],
routes: Array.isArray(templateForm.template.routes) ? templateForm.template.routes : [],
fields: templateForm.template.fields || [],
routes: templateForm.template.routes || [],
position: 0,
settings: { emailOwnerOnSubmission: true },
createdAt: new Date(),
Expand Down

0 comments on commit 5650e53

Please sign in to comment.