mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
enable bill storing
This commit is contained in:
committed by
Thomas Ruoff
parent
df6ec51af9
commit
ec1b2e9629
56
pages/api/booking/[uuid]/index.ts
Normal file
56
pages/api/booking/[uuid]/index.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
import { BookingDocument } from '../../../../db/booking'
|
||||
import { BOOKING_STATUS } from '../../../../db/enums'
|
||||
import { getBookingByUUID } from '../../../../db/index'
|
||||
|
||||
export default async function userHandler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
) {
|
||||
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)
|
||||
const readonlyProps = Object.keys(req.body).filter(
|
||||
(key) => key !== 'status'
|
||||
)
|
||||
|
||||
if (readonlyProps.length) {
|
||||
res
|
||||
.status(400)
|
||||
.end(
|
||||
`The following attributes cannot be changed: ${readonlyProps.join(
|
||||
', '
|
||||
)}`
|
||||
)
|
||||
break
|
||||
}
|
||||
|
||||
if (!Object.values(BOOKING_STATUS).includes(req.body.status)) {
|
||||
res
|
||||
.status(400)
|
||||
.end(
|
||||
`The attribute status can only be: ${Object.values(
|
||||
BOOKING_STATUS
|
||||
).join(', ')}`
|
||||
)
|
||||
break
|
||||
}
|
||||
|
||||
booking.status = req.body.status
|
||||
await booking.save()
|
||||
res.status(200).json(booking.toJSON())
|
||||
break
|
||||
default:
|
||||
res.setHeader('Allow', ['POST'])
|
||||
res.status(405).end(`Method ${method} Not Allowed`)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user