rename api end url to bookings

This commit is contained in:
Thomas Ruoff
2021-06-21 23:35:00 +02:00
parent 3babb39ec2
commit 718ed41f8d
13 changed files with 15 additions and 15 deletions

View File

@@ -0,0 +1,44 @@
import { Bill } from '../../../../db/bill'
import { createBill, patchBill } from '../../../../db/index'
import withSession, { isAdminSession } from '../../../../lib/session'
export default withSession(async function billHandler(req, res): Promise<void> {
if (!isAdminSession(req)) {
res.status(403).send({ message: 'Not Authorized' })
return
}
const {
method,
query: { uuid: uuids },
} = req
const bookingUUID = Array.isArray(uuids) ? uuids[0] : uuids
let bill: Bill
switch (method) {
case 'POST':
try {
bill = await createBill(bookingUUID, req.body)
res.status(200).json(bill)
} catch (e) {
console.error(e)
res.status(500).end(`Internal Server Error...Guru is meditating...`)
return
}
break
case 'PATCH':
try {
bill = await patchBill(bookingUUID, req.body)
res.status(200).json(bill)
} catch (e) {
console.error(e)
res.status(500).end(`Internal Server Error...Guru is meditating...`)
return
}
break
default:
res.setHeader('Allow', ['POST', 'PATCH'])
res.status(405).end(`Method ${method} Not Allowed`)
}
})