improve booking call

This commit is contained in:
Thomas Ruoff
2020-08-01 14:31:19 +02:00
parent 4089fcc944
commit 027cf45faa

View File

@@ -1,11 +1,23 @@
import { createBooking } from '../../db/index'
import { Error } from 'mongoose'
export default async function userHandler(req, res) {
const { method } = req
switch (method) {
case 'POST':
const data = await createBooking(req.body)
res.status(200).json(data)
try {
const data = await createBooking(req.body)
res.status(200).json(data)
} catch (e) {
console.error(e)
if (e instanceof Error.ValidatorError) {
res.status(400).end(e.message)
return
}
res.status(500).end(`Internal Server Error...Guru is meditating...`)
}
break
default:
res.setHeader('Allow', ['POST'])