adds message and full error in eventtype/new

This commit is contained in:
Agusti Fernandez Pardo
2022-03-25 01:52:13 +01:00
parent f4d889e87b
commit f6371c3b75
+5 -9
View File
@@ -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<Data>) {
async function createEventType(req: NextApiRequest, res: NextApiResponse<ResponseData>) {
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