mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 23:17:12 +01:00
introduce jsx files
This commit is contained in:
committed by
Thomas Ruoff
parent
2921cee220
commit
7ca2322717
34
pages/api/booking/index.jsx
Normal file
34
pages/api/booking/index.jsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { createBooking } from '../../../db/index'
|
||||
import { Error } from 'mongoose'
|
||||
|
||||
import { sendReceivedBookingMail } from '../../../helpers/mail'
|
||||
|
||||
export default async function userHandler(req, res) {
|
||||
const { method } = req
|
||||
|
||||
let booking
|
||||
|
||||
switch (method) {
|
||||
case 'POST':
|
||||
try {
|
||||
booking = await createBooking(req.body)
|
||||
res.status(200).json(booking)
|
||||
} 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...`)
|
||||
return
|
||||
}
|
||||
|
||||
await sendReceivedBookingMail(booking)
|
||||
console.log('sent receivedBookingMail')
|
||||
break
|
||||
default:
|
||||
res.setHeader('Allow', ['POST'])
|
||||
res.status(405).end(`Method ${method} Not Allowed`)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user