diff --git a/pages/api/event-types/new.ts b/pages/api/event-types/new.ts index accfb24eab..7f46aceaee 100644 --- a/pages/api/event-types/new.ts +++ b/pages/api/event-types/new.ts @@ -12,25 +12,21 @@ const validate = withValidation({ mode: "body", }); -type Data = { +type ResponseData = { data?: EventType; + message?: string; error?: string; }; -async function createEventType(req: NextApiRequest, res: NextApiResponse) { +async function createEventType(req: NextApiRequest, res: NextApiResponse) { const { body, method } = req; if (method === "POST") { const safe = schema.safeParse(body); if (safe.success && safe.data) { await prisma.eventType - .create({ - data: safe.data, - }) + .create({ data: safe.data }) .then((event) => res.status(201).json({ data: event })) - .catch((error) => { - console.log(error); - res.status(400).json({ error: "Could not create event type" }); - }); + .catch((error) => res.status(400).json({ message: "Could not create event type", error: error })); } } else { // Reject any other HTTP method than POST