mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
improve booking call
This commit is contained in:
@@ -1,11 +1,23 @@
|
|||||||
import { createBooking } from '../../db/index'
|
import { createBooking } from '../../db/index'
|
||||||
|
import { Error } from 'mongoose'
|
||||||
|
|
||||||
export default async function userHandler(req, res) {
|
export default async function userHandler(req, res) {
|
||||||
const { method } = req
|
const { method } = req
|
||||||
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case 'POST':
|
case 'POST':
|
||||||
|
try {
|
||||||
const data = await createBooking(req.body)
|
const data = await createBooking(req.body)
|
||||||
res.status(200).json(data)
|
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
|
break
|
||||||
default:
|
default:
|
||||||
res.setHeader('Allow', ['POST'])
|
res.setHeader('Allow', ['POST'])
|
||||||
|
|||||||
Reference in New Issue
Block a user