mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 22:47:15 +01:00
move admin api to /admin
This commit is contained in:
43
pages/api/admin/booking/[uuid]/bill.ts
Normal file
43
pages/api/admin/booking/[uuid]/bill.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { BillDocument } from '../../../../../db/bill'
|
||||
import { createBill, patchBill } from '../../../../../db/index'
|
||||
import withSession, { isAdminSession } from '../../../../../lib/session'
|
||||
|
||||
export default withSession(async function billHandler(req, res) {
|
||||
if (!isAdminSession(req, res)) {
|
||||
return
|
||||
}
|
||||
|
||||
const {
|
||||
method,
|
||||
query: { uuid: uuids },
|
||||
} = req
|
||||
const bookingUUID = Array.isArray(uuids) ? uuids[0] : uuids
|
||||
|
||||
let bill: BillDocument
|
||||
|
||||
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`)
|
||||
}
|
||||
})
|
||||
32
pages/api/admin/booking/[uuid]/index.ts
Normal file
32
pages/api/admin/booking/[uuid]/index.ts
Normal 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`)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user