move admin api to /admin

This commit is contained in:
Thomas Ruoff
2020-11-02 22:44:27 +01:00
parent d440d0e07e
commit 19c8bc7be2
5 changed files with 127 additions and 10 deletions

View File

@@ -0,0 +1,32 @@
import { BookingDocument } from '../../../../../db/booking'
import { getBookingByUUID } from '../../../../../db/index'
import withSession, { isAdminSession } from '../../../../../lib/session'
export default withSession(async function bookingHandler(req, res) {
if (!isAdminSession(req, res)) {
return
}
const {
method,
query: { uuid: uuids },
} = req
const uuid = Array.isArray(uuids) ? uuids[0] : uuids
let booking: BookingDocument
switch (method) {
case 'PATCH':
booking = await getBookingByUUID(uuid)
// FIXME: validate all the things
booking.set(req.body)
await booking.save()
res.status(200).json(booking.toJSON())
break
default:
res.setHeader('Allow', ['PATCH'])
res.status(405).end(`Method ${method} Not Allowed`)
}
})